CS3381 OOP - LAB Manual II CSE NEW
CS3381 OOP - LAB Manual II CSE NEW
LAB MANUAL
CS3381 – OBJECT ORIENTED PROGRAMMING LABORATORY
Prepared By
Mr. V.GURUNATHAN
ASSISTANT PROFESSOR
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
CS3381-OBJECT ORIENTED PROGRAMMING LABORATORY
OBJECTIVES:
LIST OF EXPERIMENTS:
1. Solve problems by using sequential search, binary search, and quadratic sorting algorithms (selection,
insertion)
2. Develop stack and queue data structures using classes and objects.
3. Develop a java application with an Employee class with Emp_name, Emp_id, Address, Mail_id,
Mobile_no as members. Inherit the classes, Programmer, Assistant Professor, Associate Professor and
Professor from employee class. Add Basic Pay (BP) as the member of all the inherited classes with
97% of BP as DA, 10 % of BP as HRA, 12% of BP as PF, 0.1% of BP for staff club funds. Generate
pay slips for the employees with their gross and net salary.
4. Write a Java Program to create an abstract class named Shape that contains two integers and an empty
method named printArea(). Provide three classes named Rectangle, Triangle and Circle such that each
one of the classes extends the class Shape. Each one of the classes contains only the method
printArea( ) that prints the area of the given shape.
5. Solve the above problem using an interface.
6. Implement exception handling and creation of user defined exceptions
7. Write a java program that implements a multi-threaded application that has three threads. First thread
generates a random integer every 1 second and if the value is even, the second thread computes the
square of the number and prints. If the value is odd, the third thread will print the value of the cube of
the number.
8. Write a program to perform file operations.
9. Develop applications to demonstrate the features of generics classes.
10. Develop applications using JavaFX controls, layouts and menus.
11. Develop a mini project for any application using Java concepts.
AIM
ALGORITHM:
1. Start
2. Import the needed packages.
3. Declare the variables.
4. Get the number of elements in the array and store it in a variable n.
5. Get the elements of the array.
6. Get the value to be searched and store in the variable data.
7. Check the value in data with the elements in the array.
8. Once the data is found ,print the location of the data.
9. When the data is not found in the array, print the data is not in the array.
10. Stop
PROGRAM:
import java.io.*;
import java.util.Scanner;
public class LinearSearch
{
public static void main(String args[])
{
int i, n, data, array[];
Scanner in = new Scanner(System.in);
System.out.println("Enter number of elements:");
n = in.nextInt();
array = new int[n];
for (i = 0;i< n; i++)
{
System.out.println("Enter the element:"+(i+1));
array[i] = in.nextInt();
}
System.out.println("Enter value to find");
data = in.nextInt();
for (i = 0; i< n; i++)
{
if (array[i] == data)
{
System.out.println(data + " is present at location " + (i+ 1) );
break;
}
}
if (i== n)
System.out.println(data +" is not present in the array");
}
}
OUTPUT:
RESULT:
Thus the java program for linear search has been implemented successfully.
EX NO: 1.b) BINARY SEARCH
DATE:
AIM:
ALGORITHM:
1. Start
2. Import the needed header files.
3. Declare an array variable arr.
4. Store the data to be searched in the key variable.
5. Find the element in the middle position .
6. Compare the key elements with the middle element.
7. If key = middle element, then return the mid index position.
8. If key>middle element, then the key lies in the right half of the array. Repeat steps 4,5 and 6
on the right half of the array.
9. If key<middle element, then the key lies in the left half of the array. Repeat steps 4,5 and 6
on the left half of the array.
10. Stop
PROGRAM:
import java.lang.*;
import java.util.*;
import java.io.*;
class Binary
{
public static void binarysearch(int arr[], int first, int last, int key)
{
int pos;
int mid = (first + last)/2;
while( first <last )
{
if ( arr[mid] <key )
{
first = mid + 1;
}else if ( arr[mid] == key )
{
pos=mid+1;
System.out.println("Element is found at index: " + pos);
break;
}
else
{
last = mid - 1;
}
mid = (first + last)/2;
}
if ( first > last )
{
System.out.println("Element is not found!");
}
}
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int n;
System.out.println("Enter the number of elements");
n=sc.nextInt();
int arr[]=new int[n];
System.out.println("Enter the elements:");
for(int i=0;i<n;i++)
{
arr[i]=sc.nextInt();
}
System.out.println("Enter the element to be searched");
int key = sc.nextInt();
int last=arr.length-1;
binarysearch(arr,0,last,key);
}
OUTPUT:
RESULT :
AIM:
ALGORITHM:
1. Start
2. Set MIN to location 0
3. Search the minimum element in the list
4. Swap with value at location MIN
5. Increment MIN to point to next element
6. Repeat until the list is sorted
7. Stop
PROGRAM:
import java.util.*;
class SelectionSort
{
public static void main(String args[])
{
int size;
Scanner in=new Scanner(System.in);
System.out.println("Enter the no.of elements in the array");
size=in.nextInt();
int array[]=new int[size];
System.out.println("Enter the elements");
for(int j=0;j<size;j++)
{
array[j]=in.nextInt();
}
RESULT:
Thus the java program to implement selection sort was executed successfully.
EX NO: 1.d) INSERTION SORT
DATE
AIM:
ALGORITHM:
1. Start
2. If the element is the first element, assume that it is already sorted. Return 1.
3. Pick the next element, and store it separately in a key.
4. Now, compare the key with all elements in the sorted array.
5. If the element in the sorted array is smaller than the current element, then move to the next element. Else, shift
greater elements in the array towards the right.
6. Insert the value.
7. Repeat until the array is sorted.
8. Stop
PROGRAM:
import java.util.*;
class InsertionSort
{
public static void sortInsertion(int[] arr)
{
for(int i=0;i<arr.length;++i)
{
int j = i;
}
}
}
OUTPUT:
RESULT:
Thus the java program for insertion sort has been implemented successfully.
EX.NO: 2.a) STACK
DATE :
AIM:
ALGORITHM:
1. Start
2. Include the needed header file.
3. Create a class named Operation.
4. Define all the stack operations.
5. Create a main class named StackExample.
6. Create a Stack.
7. Get the choice from the user for the stack operations.
8. Using the object invoke all the stack functions.
9. Stop
PROGRAM:
import java.util.*;
class Operation
{
void push(Stack<Integer>stack,int a)
{
stack.push(a);
}
void pop(Stack<Integer> stack)
{
int ele=(Integer)stack.pop();
System.out.println("The popped element:"+ele);
}
void peek(Stack<Integer> stack)
{
int ele=(Integer)stack.peek();
System.out.println("The top element of the stack:"+ele);
}
void search(Stack<Integer>stack,int a)
{
int pos=(Integer)stack.search(a);
if(pos==0)
System.out.println("Element not found");
else
System.out.println("Element is found in the position"+pos);
}
class StackExample
{
public static void main(String[] args)
{
Stack<Integer> stack= new Stack<Integer>();
Scanner in=new Scanner(System.in);
Operation ob=new Operation();
int ch,data;
do
{
System.out.println("\n1.Push\n2.Pop\n3.Peek\n4.Search\n5.Exit\nEnter the choice:");
ch=in.nextInt();
switch(ch)
{
case 1:
System.out.println("Enter the data");
data=in.nextInt();
ob.push(stack,data);
System.out.println("Elements in the stack:"+stack);
break;
case 2:
ob.pop(stack);
System.out.println("Elements in the stack:"+stack);
break;
case 3:
ob.peek(stack);
break;
case 4:
System.out.println("Enter the data to be searched");
data=in.nextInt();
ob.search(stack,data);
break;
case 5:
ch=0;
break;
default:
System.out.println("Enter the proper choice");
}
}while(ch>0);
}
}
OUTPUT:
RESULT:
Thus the java application to implement Stack using classes and objects was executed successfully.
EX.NO: 2.b) QUEUE
DATE:
AIM:
ALGORITHM:
PROGRAM:
import java.util.*;
class Operation
{
void enqueue(Queue<Integer> queue,int a)
{
queue.add(a);
}
void dequeue(Queue<Integer> queue)
{
int ele=(Integer)queue.poll();
System.out.println("The popped element:"+ele);
}
void peek(Queue<Integer> queue)
{
int ele=(Integer)queue.peek();
System.out.println("The head of the queue:"+ele);
}
}
class QueueExample
{
public static void main(String[] args)
{
Queue<Integer> queue= new LinkedList<Integer>();
Scanner in=new Scanner(System.in);
Operation ob=new Operation();
int ch,data,value;
do
{
System.out.println("\n1.Enqueue\n2.Dequeue\n3.Peek\n4.Exit\nEnter the
choice:");
ch=in.nextInt();
switch(ch)
{
case 1:
System.out.println("Enter the data");
data=in.nextInt();
ob.enqueue(queue,data);
System.out.println("Elements in the queue:"+queue);
break;
case 2:
ob.dequeue(queue);
System.out.println("Elements in the queue:"+queue);
break;
case 3:
ob.peek(queue);
break;
case 4:
ch=0;
break;
default:
System.out.println("Enter the proper choice ");
}
}while(ch>0);
}
}
OUTPUT:
RESULT:
Thus the java application to implement Queue using classes and objects was executed successfully.
EX NO: 3 PAYSLIP GENERATION USING INHERITANCE
DATE:
AIM:
To develop a java application with Employee class with Emp_name, Emp_id, Address, Mail_id, Mobile_no as
members. Inherit the classes, Programmer, Assistant Professor, Associate Professor and Professor from employee class. Add
Basic Pay (BP) as the member of all the inherited classes with 97% of BP as DA, 10 % of BP as HRA, 12% of BP as PF,
0.1% of BP for staff club fund. Generate pay slips for the employees with their gross and net salary.
.
ALGORITHM:
PROGRAM:
import java.util.*;
class Employee
{
int empid;
long mobile;
String name, address, mailid;
Scanner sc = new Scanner(System.in);
void getdata()
{
System.out.println("Enter Name of the Employee");
name = sc.nextLine();
System.out.println("Enter Mail id");
mailid = sc.nextLine();
System.out.println("Enter Address of the Employee:");
address =sc.nextLine();
System.out.println("Enter employee id ");
empid = sc.nextInt();
System.out.println("Enter Mobile Number");
mobile = sc.nextLong();
}
void display()
{
System.out.println("Employee Name: "+name);
System.out.println("Employee id : "+empid);
System.out.println("Mail id : "+mailid);
System.out.println("Address: "+address);
System.out.println("Mobile Number: "+mobile);
}
}
class Programmer extends Employee
{
double salary,bp,da,hra,pf,club,net,gross;
void getprogrammer()
{
System.out.println("Enter basic pay");
bp = sc.nextDouble();
}
void calculateprog()
{
da=(0.97*bp);
hra=(0.10*bp);
pf=(0.12*bp);
club=(0.1*bp);
gross=(bp+da+hra);
net=(gross-pf-club);
System.out.println("********************************************");
System.out.println("PAY SLIP FOR PROGRAMMER");
System.out.println("********************************************");
System.out.println("Basic Pay: Rs. "+bp);
System.out.println("DA: Rs. "+da);
System.out.println("HRA: Rs. "+hra);
bp =sc.nextDouble();
}
void calculateprofessor()
{
da=(0.97*bp);
hra=(0.10*bp);
pf=(0.12*bp);
club=(0.1*bp);
gross=(bp+da+hra);
net=(gross-pf-club);
System.out.println("************************");
System.out.println("PAY SLIP FOR PROFESSOR");
System.out.println("************************");
System.out.println("Basic Pay: Rs. "+bp);
System.out.println("DA: Rs. "+da);
System.out.println("HRA: Rs. "+hra);
System.out.println("PF: Rs. "+pf);
System.out.println("CLUB: Rs. "+club);
System.out.println("GROSS PAY: Rs. "+gross);
System.out.println("NET PAY: Rs. "+net);
}
}
class Salary
{
public static void main(String args[])
{
int choice,cont;
do
{
Scanner sc = new Scanner(System.in);
System.out.println("PAYROLL");
System.out.println(" 1.PROGRAMMER \n2.ASSISTANT PROFESSOR \n 3.ASSOCIATE PROFESSOR \n
4.PROFESSOR ");
System.out.println("Enter Your Choice:");
choice=sc.nextInt();
switch(choice)
{
case 1:
{
Programmer p=new Programmer();
p.getdata();
p.getprogrammer();
p.display();
p.calculateprog();
break;
}
case 2:
{
Asstprofessor asst=new Asstprofessor();
asst.getdata();
asst.getasst();
asst.display();
asst.calculateasst();
break;
}
case 3:
{
Associateprofessor asso=new Associateprofessor();
asso.getdata();
asso.getassociate();
asso.display();
asso.calculateassociate();
break;
}
case 4:
{
Professor prof=new Professor();
prof.getdata();
prof.getprofessor();
prof.display();
prof.calculateprofessor();
break;
}
default:
System.out.println(“Enter the proper choice:”);
}
System.out.print("Please enter 0 to quit and 1 to continue: ");
cont=sc.nextInt();
}while(cont==1);
}
}
OUTPUT:
RESULT
Thus the Java application to generate pay slip for different category of employees was implemented
using inheritance and the program was executed successfully.
EX.NO:4 ABSTRACT CLASS
DATE :
AIM:
To write a Java Program to create an abstract class named Shape that contains two integers and an empty
method named printArea(). Provide three classes named Rectangle, Triangle and Circle such that each one of the
classes extends the class Shape. Each one of the classes contains only the method printArea() that prints the area of the
given shape.
ALGORITHM:
PROGRAM:
import java.util.*;
abstract class Shape
{
public int x, y;
public abstract void printArea();
}
class Rectangle extends Shape
{
public void printArea()
{
System.out.println("Area of Rectangle is " + x * y);
}
}
class Triangle extends Shape
{
public void printArea()
{
System.out.println("Area of Triangle is " + (x * y) / 2);
}
}
class Circle extends Shape
{
public void printArea()
{
System.out.println("Area of Circle is " + (22 * x * x) / 7);
}
}
class AbstractExample
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
23
OUTPUT:
RESULT:
Thus the program for calculating the area of the given shape using abstract class was executed successfully.
EX.NO : 5 INTERFACES
DATE :
AIM:
To write a Java Program to create interfaces named Data and Method that contains two integers and an empty
method named print Area(). Provide three classes named Rectangle, Triangle and Circle such that each one of the
classes implements the interfaces Data and Method . Each one of the classes contains only the method print Area () that
prints the area of the given shape.
ALGORITHM:
PROGRAM:
interface Data
{
static final int x=24,y=45;
}
interface Method
{
public void printArea();
}
class Rectangle implements Data ,Method
{
public void printArea()
{
System.out.println("Area of Rectangle is " + (x * y));
}
}
class Triangle implements Data,Method
{
void printArea()
{
System.out.println("Area of Triangle is " + (x * y) / 2);
}
}
class Circle implements Data,Method
{
public void printArea()
{
System.out.println("Area of Circle is " + (22 * x * x) / 7);
}
}
class MainShape
{
public static void main(String[] args)
{
Rectangle r = new Rectangle();
Triangle t = new Triangle();
Circle c = new Circle();
r.printArea();
t.printArea();
c.printArea();
}
}
25
OUTPUT:
RESULT:
Thus the java program to implement the interface for calculating the area of the given shape was executed
successfully.
EX. NO:6 IMPLEMENT USER DEFINED EXCEPTION HANDLING
DATE :
AIM:
ALGORITHM:
PROGRAM:
import java.util.*;
import java.io.*;
class MyException extends Exception
{
MyException(String str)
{
System.out.println(str);
}
}
class ExceptionExample
{
public static void main(String a[])
{
int no;
try
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number :");
no=sc.nextInt();
if(no<0)
{
throw new MyException("Number must be positive");
}
else
{
System.out.println(" Square root :"+Math.sqrt(no));
}
}
catch(Exception e)
{
}
}
27
OUTPUT:
RESULT:
Thus the program for user defined exception handling was executed successfully.
EX. NO:7 MULTI THREADING IMPLEMENTATION
DATE :
AIM:
To write a java program that implements a multi-threaded application that has three threads. First thread
generates a random integer every 1 second and if the value is even, second thread computes the square of the number
and prints. If the value is odd, the third thread will print the value of cube of the number.
ALGORITHM:
PROGRAM:
import java.util.*;
import java.lang.*;
class EvenThread implements Runnable
{
public int x;
public EvenThread(int x)
{
this.x = x;
}
public void run()
{
System.out.println("New Thread "+ x +" is EVEN \n Square of " + x + " is: " + x *x);
}
}
class OddThread implements Runnable
{
public int x;
public OddThread(int x)
{
this.x = x;
}
public void run()
{
System.out.println("New Thread "+ x +" is ODD\n Cube of " + x + " is: " + x * x *x);
}
}
class RandomThread extends Thread
{
public void run()
{
int num = 0;
Random r = new Random();
try
{
for (int i = 0; i < 5; i++)
{
num = r.nextInt(100);
System.out.println("Generated Random Number is " + num);
if (num % 2 == 0)
{
Thread t1 = new Thread(new EvenThread(num));
29
t1.start();
}
else
{
Thread t2 = new Thread(new OddThread(num));
t2.start();
}
Thread.sleep(1000);
System.out.println("--------------------------------------");
}
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
}
}
public class ThreadExample
{
public static void main(String args[])
{
RandomThread rt = new RandomThread();
rt.start();
}
}
30
OUTPUT:
RESULT:
AIM
ALGORITHM:
PROGRAM:
import java.io.*;
import java.util.*;
class FileOperation
{
public static void main(String args[]) throws IOException
{
Scanner sc=new Scanner(System.in);
System.out.println(“Enter the name of the file to be created”);
String str=sc.nextLine();
File f=new File(str);
InputStream in = new FileInputStream(“D:\\student.txt”);
OutputStream out=new FileOutputStream(f);
DataInputStream dis = new DataInputStream(in);
DataOutputStream dos=new DataOutputStream(out);
String filename=f.getPath();
System.out.println(“Name of the created file:”+filename);
String path=f.getAbsolutePath();
System.out.println(“Path of the created file:”+path);
int count = in.available();
System.out.println(“Size of the data in file:”+count);
byte[] data = new byte[count];
System.out.println(“Copying the datas to the file :”+f+”.txt”);
dis.read(data);
System.out.println(“Data in the file: “+filename);
for(int i=0;i<count;i++)
{
char k=(char)data[i];
out.write(data[i]);
System.out.print(k+””);
}
}
}
32
OUTPUT:
RESULT:
Thus the java program to implement the different file operations was executed successfully.
EX. NO:9 GENERIC METHOD
DATE :
AIM:
To write a java program for finding the maximum value from the given integer and float array using a generic
method.
ALGORITHM:
PROGRAM:
import java.lang.*;
import java.util.*;
class Maximum
{
public static <E extends Comparable<E>> E max(E[] list)
{
E max = list[0];
for (int i = 1; i < list. length; i++)
{
if (list[i].compareTo(max)>0)
{
max = list[i];
}
}
return max;
}
}
class GenericExample
{
public static void main (String args[])
{
Integer arr1[] = {10, 15,45,34,75,25,89,64,72,5};
String str=arr1.toString();
System.out.println("\nElements in the integer array:\n");
for(int i=0;i<10;i++)
{
System.out.print(arr[i]+" ");
}
System.out.println("\nMaximum: "+Maximum.max(arr1));
Float arr2[] = {1.1f, 25.3f,3.1f,5.5f,13.7f,8.4f,15.6f,46.5f,76.5f,34.9f};
System.out.println("\nElements in the float array:\n");
for(int j=0;j<10;j++)
{
System.out.print(arr2[j]+" ");
}
System.out.println("\n\nMaximum: "+Maximum.max(arr2));
}
}
34
OUTPUT:
RESULT:
Thus the java program for finding the maximum value from the given integer and float array using a generic
method was implemented successfully.
EX. NO:10 JAVAFX CONTROLS
DATE :
AIM:
ALGORITHM:
PROGRAM:
package application;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class MenuExample extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
// TODO Auto-generated method stub
BorderPane root = new BorderPane();
Scene scene = new Scene(root,200,300);
MenuBar menubar = new MenuBar();
Menu FileMenu = new Menu("File");
MenuItem filemenu1=new MenuItem("new");
MenuItem filemenu2=new MenuItem("Save");
MenuItem filemenu3=new MenuItem("Exit");
Menu EditMenu=new Menu("Edit");
MenuItem EditMenu1=new MenuItem("Cut");
MenuItem EditMenu2=new MenuItem("Copy");
MenuItem EditMenu3=new MenuItem("Paste");
EditMenu.getItems().addAll(EditMenu1,EditMenu2,EditMenu3);
root.setTop(menubar);
FileMenu.getItems().addAll(filemenu1,filemenu2,filemenu3);
menubar.getMenus().addAll(FileMenu,EditMenu);
primaryStage.setScene(scene);
36
primaryStage.show();
}
}
OUTPUT:
RESULT:
Thus the menu application created successfully using JavaFX controls, layouts and menus.
EX. NO:11.a MINI PROJECT - OPAC SYSTEM
DATE :
AIM:
To develop a mini project OPAC system for library using Java concepts.
ALGORITHM:
public Data()
{
super("My Application"); Container c =
getContentPane(); c.setLayout(new
GridLayout(5,1));
p.add(next);
next.addActionListener(this);pack();
setVisible(true); addWindowListener(new
WIN());
}
38
public static void main(String args[])
{
Data d = new Data();try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); conn =
DriverManager.getConnection("jdbc:odbc:stu");
// cust is the DSN Name
stat = conn.createStatement();
res = stat.executeQuery("Select * from stu"); // stu is the table nameres.next();
}
catch(Exception e)
{
System.out.println("Error" +e);
}
d.showRecord(res);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == next)
{
try
{
res.next();
}
catch(Exception e)
{
}
showRecord(res);
}
}
public void showRecord(ResultSet res)
{
try
{
id.setText(res.getString(2));
name.setText(res.getString(3));
}
catch(Exception e)
{
}
}//end of the main
39
NOTE:
Create a new Database
Administrative Tools.
ODBC Data Source Administrator
OUTPUT:
To Compile:
javac Data.java
To Run:
java Data
RESULT:
Thus the program to develop the simple OPAC for the libraries is executedsuccessfully.
EX. NO:11.b MINI PROJECT
DATE :
ALGORITHM:
1. Open Android Studio and then click on File-> New -> New project.
2. Create a new Android application project with an application name: "Calculator" and package name:
"comjavahelps.calculator".
3. By default, Android uses a green Android robot icon. In this project, we are going to use a custom application
icon.
4. Right click on the "mipmap" folder and select New~ Image Asset
5. Replace the content of the activity_main.xml file by the following code. This code creates a TextView as the
calculator number screen and some necessary buttons. TextView is used instead of EditText, in order to
prevent manual user input using the default keypad of Android.
6. Right click on the "drawable"folder and select New Drawable resource file.
7. This drawable resource is used to decorate the buttons of the calculator. There are two gradient shapes in this
code; one is for button pressed state and another for the normal state.
8. For all the buttons in the activiy_main.xml, add a property "android:background".
9. Modify the MainActivity java as provided below. Complete description of the code is provided in comments.
10. Save all the changes and run the application.
package com.example.calculator
import androidx.appcompat.app.AppCompatActivity:
import android.os.Bundle;
import android.view. View;
import android.widget.Button;
import android.widget. TextView;
45
String operator;
TextView result Text View;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initControl0:
initControlListener():
buttonó.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onNumberButtonClicked("6");
button9.setOnClickListener(new View.OnClickListener) {
@Override
public void onClick(View v){
onNumberButtonClicked("9");
buttonClear.setOnClickListener(new View.OnClickListener) {
@Override
public void onClick(View v) {
onClearButtonClicked):
buttonAdd.setOnClickListener(new View.OnClickListener) {
@Override
public void onClick(View v) {
onOperatorButtonClicked("+"):
buttonMul.setOnClickListener(new View.OnClickListener() @Override
public void onClick(View v) {
onOperatorButtonClicked("X");
buttonDiv.setOnClickListener(new View.OnClickListener) {
@Override
public void onClick(View v) {
onOperatorButtonClicked("/");
onClearButtonClicked);
this.operator = operator;
android:id="@+id/textview_result"
android:textSize="60sp"
android:textAlignment="viewEnd"/>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/buttonl"
android:text="|"
android:layout_weight="|"
android:textSize="20sp"/>
<Button
android:id="@+id/button2"
android:text="2"
android:layout_weight="|"
android:textSize="20sp"/>
<Button
android:id="@+id/button3"
android:text="3"
android:layout weight="1"
android:textSize="20sp"/>
<Button
android:id="@+id/buttonAdd"
android:text="+"
android:layout weight="I" android:textSize="20sp"/>
<TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"-
<Button
android:id="@+id/button4"
andro "4"
android:layout_weight="I"
android:textSize="20sp"/>
<Button
android:id="@+id/buttons"
android:text="5"
android:layout_weight="1"
android:textSize="20sp"/>
<Button
android:id="@+id/button6"
android:text="6"
android: layout_weight="|" android:textSize="20sp"/>
<Button
android:id="@+id/buttonSub"
android:text="-"
android:layout_weight="1"
android:textSize="20sp">
48
<TableRow>
<TableRow
android:layout_width="match _parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button7"
android:text="7"
android:layout_weight="T"
android:textSize="20sp"/>
<Button
android:id="@+id/button8"
android:text="8"
android:layout_weight="|"
android:textSize="20sp"/>
<Button
android:id="@+id/button9"
android:text="9"
android:layout_weight="1"
android:textSize="20sp"/>
<Button
android:id="@+idbuttonMul"
android:text="*"
android:layout weight="|"
android:textSize="20sp"/>
TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/buttonClear"
android:text="CLEAR"
android:layout weight="|"
android:textSize="20sp"/>
<Button
android:id="@+id/button0"
android:text="0"
android:layout weight="|"
android:textSize="20sp"/>
<Button
android:id="@+id/buttonEqual"
android:text="="
android:layout weight="T" android:textSize="20sp"/>
<Button
android:id="@+id/buttonDiv"
android:text="/"
android:layout_weight="|"
android:textSize="20sp"/> <TableRow>
STablelayout>
49