KGISL Institute of Technology
KGISL Institute of Technology
LAB MANUAL
CS8383
OBJECT ORIENTED PROGRAMMING
LABORATORY
Prepared By,
Rajasekaran S
Assistant Professor
KGISL Institute of Technology
Coimbatore.
Email:proffraja@gmail.com
Rajasekaran S /AP/ IT
KGISL Institute of
Technology
INDEX
S No Experiment Marks
Sign
Important Links
Rajasekaran
S /AP/ IT
KGISL
Institute of Technology
Ex.No: 1
Electricity Bill Calculator
Date:
Aim:
Algorithm:
Rajasekaran S /AP/ IT
KGISL
Institute of Technology
Coding
import java.util.Scanner;
class EBConsumer {
int consumer_number;
String consumer_name;
int previous_month_reading;
int current_month_reading;
int units_consumed;
boolean isDomestic = false;
double bill_ammount;
Rajasekaran S /AP/ IT
KGISL Institute
of Technology
sum = sum + 4;
else
sum = sum + 6;
}
}
else {
for (int i = 0; i <= number_of_units_consumed; i++) {
if (i <= 100)
sum = sum + 2;
else if (i > 100 && i <= 200)
sum = sum + 4.5;
else if (i > 200 && i <= 500)
sum = sum + 6;
else
sum = sum + 7;
}
}
this.bill_ammount = sum;
}
Rajasekaran S /AP/ IT
KGISL Institute of
Technology
Output:
Result:
The Java console application for electricity bill generator was developed
and tested
successfully.
Rajasekaran S
/AP/ IT
KGISL
Institute of Technology
Ex.No: 2
Unit Converters Application using packages
Date:
Aim:
Algorithm:
Rajasekaran S /AP/ IT
KGISL
Institute of Technology
Step 8.2 If option 2 selected get in HOURS and display HOURS * 3600 as
SECONDS
Step 8.3 If option 3 selected get in MINUTES and display MINUTES / 60 as
HOURS
Step 8.2 If option 4 selected get in SECONDS and display SECONDS / 3600
as
HOURS.
Step 8.5 If option 5 selected exit from tim converter choice and goto
step 2
Step 9 If user selects exit then display Thank You !!! and exit from the system
Step 10 Stop the process
Coding:
Currency.java
package com.raja.oopslab.converters;
import java.util.Scanner;
Rajasekaran S /AP/ IT
KGISL Institute of
Technology
case 1:
System.out.println("Enter in DOLLER");
money = input.nextDouble();
System.out.println(money+" DOLLER is equal to
"+Currency.convertDOLLARtoINR(money)+" INR");
break;
case 2:
System.out.println("Enter in EURO");
money = input.nextDouble();
System.out.println(money+" EURO is equal to
"+Currency.covertEUROtoINR(money)+" INR");
break;
case 3:
System.out.println("Enter in YEN");
money = input.nextDouble();
System.out.println(money+" YEN is equal to
"+Currency.convertYENtoINR(money)+" INR");
break;
case 4:
System.out.println("Enter in INR");
money = input.nextDouble();
System.out.println(money+" INR is equal to
"+Currency.convertINRtoDOLLAR(money)+" DOLLORS");
break;
case 5:
System.out.println("Enter in INR");
money = input.nextDouble();
System.out.println(money+" INR is equal to
"+Currency.covertINRtoEURO(money)
+" EURO");
break;
case 6:
System.out.println("Enter in INR");
money = input.nextDouble();
System.out.println(money+" INR is equal to
"+Currency.convertINRtoYEN(money)
+" YEN");
break;
case 7:
break;
default:
System.out.println("Please choose valid option");
break;
}
}
}
}
Rajasekaran
S /AP/ IT
KGISL
Institute of Technology
Distance.java
package com.raja.oopslab.converters;
import java.util.Scanner;
Rajasekaran S /AP/ IT
KGISL
Institute of Technology
Time.java
package com.raja.oopslab.converters;
import java.util.Scanner;
Rajasekaran S /AP/ IT
KGISL Institute
of Technology
Main.java
import java.util.Scanner;
import com.raja.oopslab.converters.Currency;
import com.raja.oopslab.converters.Distance;
import com.raja.oopslab.converters.Time;
while(choice != 4){
System.out.println("Converters");
System.out.println("**********");
System.out.println("1. Currentcy\n2. Distance\n3. Time\n4. Exit\n\nEnter Your
Choice");
choice = input.nextInt();
switch(choice){
case 1:
Currency.userChoice();
break;
case 2:
Distance.userChoice();
break;
case 3:
Time.userChoice();
break;
case 4:
break;
default:
System.out.println("Please choose valid option");
Rajasekaran S /AP/ IT
KGISL Institute of Technology
break;
}
}
System.out.println("Thank You !!!!");
}
}
Output
Choice
Distance
Rajasekaran S /AP/ IT
KGISL Institute
of Technology
Min to Hours
Result
The java console application for converters [Currency, Distance, Time] was
developed and
tested successfully.
Rajasekaran S /AP/ IT
KGISL
Institute of Technology
Ex.No: 3
Employee Payroll System
Date:
Aim:
Algorithm:
Coding
Employee.java
package com.raja.oopslab.employee;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Scanner;
package com.raja.oopslab.employee;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Scanner;
class Employee {
String emp_name;
String emp_id;
String emp_address;
String emp_mail_id;
String emp_mobile_no;
int basic_pay;
int per_day_pay;
int current_basic_pay;
int da, hra, pf, gross_pay;
int net_pay;
int no_of_days_in_current_month;
int no_of_days_worked;
Calendar cal;
Scanner input;
Employee() {
input = new Scanner(System.in);
cal = new GregorianCalendar();
no_of_days_in_current_month =
cal.getActualMaximum(Calendar.DAY_OF_MONTH);
getUserBasicDetails();
}
Rajasekaran S /AP/ IT
KGISL
Institute of Technology
Rajasekaran S /AP/ IT
KGISL
Institute of Technology
Programmer.java
package com.raja.oopslab.employee;
public Programmer() {
super();
computeProgrammerPay();
Assistant Professor.java
package com.raja.oopslab.employee;
Associate Professor
package com.raja.oopslab.employee;
computeCurrentBasicPay("AssociateProfessor");
generatePaySlip();
displayPaySlip();
}
}
Professor
package com.raja.oopslab.employee;
Main.java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import com.raja.oopslab.employee.AssistantProfessor;
import com.raja.oopslab.employee.AssociateProfessor;
import com.raja.oopslab.employee.Programmer;
import com.raja.oopslab.employee.Professor;
while (n_choice != 5) {
System.out.println("\n\nEmployee Payroll System");
System.out.println("***********************\n");
System.out.println("1. Programmer\n2. Assistant Professor\n"
+ "3. Associate
Professor\n4. Professor\n"
+ "5. Exit\n\nEnter Your Choice");
choice = new BufferedReader(new
InputStreamReader(System.in)).readLine();
n_choice = Integer.parseInt(choice);
switch (n_choice) {
case 1:
System.out.println("Programmer Selected");
aProgrammer = new Programmer();
break;
case 2:
System.out.println("AssistantProfessor Selected");
aAssistantProfessor = new AssistantProfessor();
break;
case 3:
System.out.println("AssociateProfessor Selected");
aAssociateProfessor = new AssociateProfessor();
break;
case 4:
System.out.println("Professor Selected");
aProfessor = new Professor();
case 5:
System.out.println("Thank You !!!");
userInput.close();
break;
default:
System.out.println("Enter valid choice !!!");
break;
}
}
}}
Rajasekaran S /AP/ IT
KGISL Institute of Technology
Output:
Choices
Basic Details
Rajasekaran S /AP/ IT
KGISL Institute of Technology
Programmer
Assistant Professor
Rajasekaran S /AP/ IT
KGISL Institute of Technology
Associate Professor
Professor
Rajasekaran S /AP/ IT
KGISL Institute
of Technology
Result:
The java console application for employee payroll system was developed and
tested
successfully.
Rajasekaran S /AP/ IT
KGISL
Institute of Technology
Ex.No: 4
Java Application for ADT Stack using
Interfaces
Date:
Aim:
Algorithm:
Rajasekaran S /AP/ IT
KGISL
Institute of Technology
Coding
StackOpeations.java [Interface]
package com.raja.oopslab.stackadt;
boolean pop();
void peek();
void display();
}
CustomStack.java
package com.raja.oopslab.stackadt;
@Override
public boolean push(int number) {
try {
stack_array[current_position] = number;
current_position++;
System.out.println("The element " + number + " pushed in
the position " +
current_position);
display();
return true;
}
catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Sorry Stack Full Please do some POP's");
}
return false;
Rajasekaran S /AP/ IT
KGISL
Institute of Technology
@Override
public boolean pop() {
int poped_element;
try {
poped_element = stack_array[current_position - 1];
stack_array[current_position - 1] = -1;
current_position--;
System.out.println("Poped element is : " + poped_element);
display();
return true;
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Sorry Stack is Empty try to do some
push");
}
return false;
}
@Override
public void display() {
System.out.println("\nStack Display");
System.out.println("*************\n");
for (int i = limit - 1; i >= 0; i--)
if (stack_array[i] != -1)
System.out.println(stack_array[i]);
System.out.println("\n*************");
}
@Override
public void peek() {
int peek_element = 0;
peek_element = stack_array[current_position - 1];
System.out.println("Peek Element of the Stack is " + peek_element);
}
Main.java
import java.util.Scanner;
import com.raja.oopslab.stackadt.*;
System.out.println("\n1.PUSH\n2.POP\n3.PEEK\n4.DISPLAY\n5.EXIT");
System.out.println("Please Enter Your Choice : ");
choice = input.nextInt();
switch (choice) {
case 1:
System.out.println("Enter the Element to PUSH : ");
mystack.push(input.nextInt());
break;
case 2:
mystack.pop();
Rajasekaran S /AP/ IT
KGISL
Institute of Technology
break;
case 3:
mystack.peek();
break;
case 4:
mystack.display();
break;
case 5:
System.out.println("!!! Thank You !!!");
break;
}
}
input.close();
System.exit(0);
}
}
Output:
Choice:
Rajasekaran S /AP/ IT
KGISL Institute of Technology
Push Operation:
Rajasekaran S /AP/ IT
KGISL Institute of Technology
Rajasekaran S /AP/ IT
KGISL
Institute of Technology
Result:
The java console application for abstract data type stack using java
interface concepts is
developed and tested successfully.
Rajasekaran S /AP/ IT
KGISL
Institute of Technology
Ex.No: 5
Java Application for String Operations using
ArrayList
Date:
Aim:
Algorithm:
Coding:
StringList.java
package com.raja.oopslab.stringlist;
import java.util.ArrayList;
public StringList() {
listOfStrings = new ArrayList<String>();
}
if (cur_pos == position)
templist.add(aString);
templist.add(elememt);
cur_pos++;
}
}
listOfStrings = templist;
}
int cur_pos = 0;
int foundAt = -1;
Rajasekaran S /AP/ IT
KGISL
Institute of Technology
cur_pos++;
}
if (foundAt >= 0)
System.out.println("Your string " + aString + " found at
position " +
cur_pos);
else
System.out.println("String not found in the list");
}
Main.java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Scanner;
import com.raja.oopslab.stringlist.StringList;
choice = userInput.nextInt();
switch (choice) {
case 1:
System.out.println("Enter a String: ");
stringList.addString(userInput.next());
break;
case 2:
System.out.println("Enter a String: ");
aString = userInput.next();
System.out.println("Enter a Position to Insert: ");
Rajasekaran S /AP/ IT
KGISL Institute of
Technology
position = userInput.nextInt();
stringList.insertStringAt(position, aString);
break;
case 3:
System.out.println("Enter a String to Be Searched: ");
aString = userInput.next();
stringList.searchString(aString);
break;
case 4:
System.out.println("\nList Contains");
System.out.println("-------------");
stringList.displayList();
break;
case 5:
System.out.println("Enter a letter");
stringList.displayStringsBeginWith(userInput.next());
break;
case 6:
System.out.println("\n\nThank You !!!");
userInput.close();
System.exit(0);
break;
default:
System.out.println("Please enter valid input");
break;
}
}
}
}
Rajasekaran S
/AP/ IT
KGISL Institute of Technology
Output:
List Choices:
Append a string:
Rajasekaran S /AP/ IT
KGISL Institute of Technology
Display List:
Insert At Position:
Rajasekaran S /AP/ IT
KGISL
Institute of Technology
Search a String:
Result:
The java console application for string list operations was developed and
tested
successfully.
Rajasekaran S /AP/ IT
KGISL
Institute of Technology
Ex.No: 6
Java Application to Find the Area of different
Shapes
Date:
Aim:
Algorithm:
Rajasekaran S /AP/ IT
KGISL
Institute of Technology
Coding:
Shape.java
package com.raja.oopslanb.shapes;
Rectangle.java
package com.raja.oopslanb.shapes;
import java.util.Scanner;
@Override
public void printArea() {
System.out.println("\nRectangle");
System.out.println("---------\n");
Scanner input = new Scanner(System.in);
System.out.println("Enter Length of Rectangle : ");
this.length = input.nextDouble();
System.out.println("Enter Breadth of Rectangle : ");
this.hight = input.nextDouble();
this.area = this.length * this.hight;
System.out.println("Area of the Rectangle is : " + this.area);
}
Triangle.java
package com.raja.oopslanb.shapes;
import java.util.Scanner;
@Override
public void printArea() {
System.out.println("\nTriangle");
System.out.println("---------\n");
Scanner input = new Scanner(System.in);
System.out.println("Enter Length of Triangle : ");
this.length = input.nextDouble();
System.out.println("Enter Hight of Triangle : ");
this.hight = input.nextDouble();
this.area = 0.5 * this.length * this.hight;
System.out.println("Area of the Triangle is : " + this.area);
}
Rajasekaran S /AP/ IT
KGISL
Institute of Technology
Circle.java
package com.raja.oopslanb.shapes;
import java.util.Scanner;
@Override
public void printArea() {
System.out.println("\nCircle");
System.out.println("-------\n");
Scanner input = new Scanner(System.in);
System.out.println("Enter Radius of Circle : ");
this.length = input.nextDouble();
this.area = Math.PI * this.length * this.length;
System.out.println("Area of the Circle is : " + this.area);
}
Main.java
import com.raja.oopslanb.shapes.Rectangle;
import com.raja.oopslanb.shapes.Shape;
import com.raja.oopslanb.shapes.Triangle;
import java.util.Scanner;
import com.raja.oopslanb.shapes.Circle;
Rajasekaran S /AP/ IT
KGISL Institute of
Technology
cr.printArea();
break;
case 4:
System.out.println("\n\nThank You !!!");
userInput.close();
break;
default:
System.out.println("Please enter valid input");
break;
}
} while (choice != 4);
}
}
Rajasekaran S /AP/ IT
KGISL Institute of Technology
Output:
Choice
Rectangle
Triangle
Rajasekaran S /AP/ IT
KGISL
Institute of Technology
Circle
Result:
The Java console application to find the area of different shapes using
abstract class concept
in java was developed and tested successfully.
Rajasekaran S /AP/ IT
KGISL
Institute of Technology
Ex.No: 7
Bank Transaction System with User Exceptions
Date:
Aim:
Algorithm:
Rajasekaran S /AP/ IT
KGISL
Institute of Technology
Coding:
Customer.java
package com.raja.oopslab.exception.bank;
import java.util.Scanner;
else
balance = balance + amount;
} catch (InvalidCredit e) {
amount = input.nextInt();
creditTransaction(amount);
}
else
balance = balance - amount;
} catch (InvalidDebit e) {
amount = input.nextInt();
debitTransaction(amount);
}
Rajasekaran S /AP/ IT
KGISL
Institute of Technology
InvalidCredit.java
package com.raja.oopslab.exception.bank;
InvalidDebit.java
package com.raja.oopslab.exception.bank;
Main.java
import java.util.Scanner;
import com.raja.oopslab.exception.bank.*;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String name;
int acc_no;
System.out.println("Enter Customer Name");
name = input.next();
System.out.println("Enter account number");
acc_no = input.nextInt();
Customer aCustomer = new Customer(name, acc_no);
int choice = 0;
while(choice != 4){
System.out.println("\n1. Add Money\n2. Get Money\n3.
Details\n4. Exit");
choice = input.nextInt();
switch(choice){
case 1:
System.out.println("Enter the amount");
aCustomer.creditTransaction(input.nextInt());
break;
case 2:
System.out.println("Enter the amount");
aCustomer.debitTransaction(input.nextInt());
break;
case 3:
aCustomer.displayDetails();
break;
case 4:
System.out.println("Thank You !!!");
break;
}
}
}
}
Rajasekaran S /AP/ IT
KGISL Institute of Technology
Output:
Choice:
Display Details:
Rajasekaran S /AP/ IT
KGISL Institute of Technology
Add Money:
Get Money:
Rajasekaran S /AP/ IT
KGISL
Institute of Technology
Result:
The java console application that uses user defined exception handling
techniques was
developed and tested successfully.
Rajasekaran S /AP/ IT
KGISL
Institute of Technology
Ex.No: 8
Java Application for File Handling
Date:
Aim:
To create a Java console application to handle the files and find the file
properties
[Availability, Readable or Writeable or Both, Length of the File].
Algorithm:
Rajasekaran S /AP/ IT
KGISL
Institute of Technology
Coding:
UserFileHandler.java
package com.raja.oopslab.files;
import java.io.File;
public class UserFileHandler{
File aFile;
boolean isReadable = false;
boolean isWriteable = false;
boolean isExists = false;
int length = 0;
public UserFileHandler(String path) {
aFile = new File(path);
this.isExists = aFile.exists();
this.isReadable = aFile.canRead();
this.isWriteable = aFile.canWrite();
this.length = (int) aFile.length();
}
public void fileDetails(){
if(isExists){
System.out.println("The File "+aFile.getName()+" is Available
at:"+aFile.getParent());
if(isReadable && isWriteable)
System.out.println("File is Readable and Writeable");
else if(isReadable)
System.out.println("File is Only Readable");
else if(isWriteable)
System.out.println("File is Only Writeable");
System.out.println("Total length of the file is :"+this.length+"
bytes");
}
else
System.out.println("File does not exists ");
}
}
Main.java
import java.io.File;
import java.util.Scanner;
import com.raja.oopslab.files.*;
public class Main {
Rajasekaran S /AP/ IT
KGISL Institute of Technology
Output:
Availability of File:
Rajasekaran S /AP/ IT
KGISL
Institute of Technology
File Size:
Result:
The java console application for handling files was developed and tested
successfully.
Rajasekaran S /AP/ IT
KGISL
Institute of Technology
Ex.No: 9
Java Application for Multi threading
Date:
Aim:
To create a Java console application the uses the multi threading concepts
in java. The
Application has 3 threads one creates random number, one thread computes square of
that number
and another one computes the cube of that number.
Algorithm:
Rajasekaran S /AP/ IT
KGISL Institute
of Technology
Coding:
RandomNumberThread.java
package com.raja.oopslab.threading;
import java.util.Random;
}
value = num.nextInt(1000);
System.out.println("RandomNumberThread generated a number
"+value);
if(value % 2 == 0)
new SquareGenThread(value).start();
else
new CubeGenThread(value).start();
}
}
}
SquareGenThread.java
package com.raja.oopslab.threading;
}
this.squre = this.number * this.number;
System.out.println("SquareGenThread--> Square of "+number+" is
"+squre);
}
}
CubeGenThread.java
package com.raja.oopslab.threading;
Rajasekaran
S /AP/ IT
KGISL Institute of
Technology
int squre;
public CubeGenThread(int number) {
this.number = number;
}
@Override
public void run(){
try {
this.sleep(2000);
} catch (InterruptedException e) {
}
this.squre = this.number * this.number * this.number;
System.out.println("CubeGenThread--> Square of "+number+" is "+squre);
}
}
Main.java
import java.util.Random;
import com.raja.oopslab.threading.RandomNumberThread;
public class Main {
public static void main(String[] args) {
new RandomNumberThread().start();
}
}
Rajasekaran S
/AP/ IT
KGISL
Institute of Technology
Output:
Result:
The java console application for multithreading was developed and tested
successfully.
Rajasekaran S /AP/ IT
KGISL
Institute of Technology
Ex.No: 10
Java Application for Generic Max Finder
Date:
Aim:
To create a Java console application that finds the maximum in a array based
on the type of
the elements using generic functions in java.
Algorithm:
Rajasekaran S /AP/ IT
KGISL Institute of
Technology
Coding:
class GenericMax {
public <T extends Comparable<T>> void maxFinder (T[] array){
T max = array[0];
for(T element: array){
System.out.println(element);
if(element.compareTo(max) > 0)
max = element;
}
System.out.println("Max is : "+max);
}
}
Rajasekaran S
/AP/ IT
KGISL
Institute of Technology
Output:
Result:
The java console application for finding generic max of given elements was
developed and
tested successfully.
Rajasekaran S /AP/ IT
KGISL
Institute of Technology
Ex.No: 11
Calculator Application using java AWT packages
Date:
Aim:
To create a Java GUI application that mimics the basic and advanced
functionalities of a
scientific calculator.
Algorithm:
Rajasekaran S /AP/ IT
KGISL Institute of
Technology
Coding:
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
Button n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,point,equal;
Button plus,minus,multiply, divide;
Button m_plus,m_minus,clear,advanced;
TextField display;
String op1,op2,result;
String op_flag;
String data;
double dop1,dop2,dresult;
boolean flag_advanced=true;
public Numpan(TextField display) {
this.display = display;
setLayout(new GridLayout(0,4));
n0 = new Button("0");
n0.setActionCommand("zero");
n0.addActionListener(this);
n1 = new Button("1");
n1.setActionCommand("one");
n1.addActionListener(this);
n2 = new Button("2");
n2.setActionCommand("two");
n2.addActionListener(this);
n3 = new Button("3");
n3.setActionCommand("three");
n3.addActionListener(this);
n4 = new Button("4");
n4.setActionCommand("four");
n4.addActionListener(this);
n5 = new Button("5");
n5.setActionCommand("five");
n5.addActionListener(this);
n6 = new Button("6");
n6.setActionCommand("six");
n6.addActionListener(this);
Rajasekaran S /AP/
IT
KGISL Institute of Technology
n7 = new Button("7");
n7.setActionCommand("seven");
n7.addActionListener(this);
n8 = new Button("8");
n8.setActionCommand("eight");
n8.addActionListener(this);
n9 = new Button("9");
n9.setActionCommand("nine");
n9.addActionListener(this);
add(m_plus);
add(m_minus);
add(clear);
add(advanced);
add(n1);
add(n2);
Rajasekaran S /AP/ IT
KGISL Institute of
Technology
add(n3);
add(plus);
add(n4);
add(n5);
add(n6);
add(minus);
add(n7);
add(n8);
add(n9);
add(multiply);
add(point);
add(n0);
add(equal);
add(divide);
}
public String getDisplayText(){
return display.getText().toString();
}
public void setDisplay(String text){
display.setText(text);
}
public void clearDisplay(){
System.out.println("Clear Called");
setDisplay("");
data = "";
}
}
else{
plus.setLabel("+");
plus.setActionCommand("plus");
minus.setLabel("-");
minus.setActionCommand("minus");
multiply.setLabel("x");
multiply.setActionCommand("multiply");
divide.setLabel("/");
divide.setActionCommand("divide");
}
}
@Override
public void actionPerformed(ActionEvent e) {
data = getDisplayText();
switch(e.getActionCommand()){
Rajasekaran S /AP/ IT
KGISL Institute of Technology
case "zero":
setDisplay(data+"0");
break;
case "one":
setDisplay(data+"1");
break;
case "two":
setDisplay(data+"2");
break;
case "three":
setDisplay(data+"3");
break;
case "four":
setDisplay(data+"4");
break;
case "five":
setDisplay(data+"5");
break;
case "six":
setDisplay(data+"6");
break;
case "seven":
setDisplay(data+"7");
break;
case "eight":
setDisplay(data+"8");
break;
case "nine":
setDisplay(data+"9");
break;
case "plus":
op1 = data;
op_flag = "plus";
clearDisplay();
break;
case "minus":
op1 = data;
op_flag = "minus";
clearDisplay();
break;
case "multiply":
op1 = data;
op_flag = "multiply";
clearDisplay();
break;
case "divide":
op1 = data;
op_flag = "divide";
clearDisplay();
break;
case "clear":
clearDisplay();
break;
case "advanced":
if(flag_advanced){
changeAdvanced(true);
flag_advanced = false;
Rajasekaran S /AP/ IT
KGISL Institute of Technology
}
else{
changeAdvanced(false);
flag_advanced = true;
}
break;
case "sin":
op1 = data;
setDisplay(String.valueOf(Math.sin(Double.valueOf(op1))));
break;
case "cos":
op1 = data;
setDisplay(String.valueOf(Math.cos(Double.valueOf(op1))));
break;
case "tan":
op1 = data;
setDisplay(String.valueOf(Math.tan(Double.valueOf(op1))));
break;
case "log":
op1 = data;
setDisplay(String.valueOf(Math.log(Double.valueOf(op1))));
break;
case "equal":
switch(op_flag){
case "plus":
op2 = data;
clearDisplay();
dop1 = Double.parseDouble(op1);
dop2 = Double.parseDouble(op2);
dresult = dop1 + dop2;
result = String.valueOf(dresult);
setDisplay(result);
op_flag = "";
break;
case "minus":
op2 = data;
clearDisplay();
dop1 = Double.parseDouble(op1);
dop2 = Double.parseDouble(op2);
dresult = dop1 - dop2;
result = String.valueOf(dresult);
setDisplay(result);
op_flag = "";
break;
case "multiply":
op2 = data;
clearDisplay();
dop1 = Double.parseDouble(op1);
dop2 = Double.parseDouble(op2);
dresult = dop1 * dop2;
result = String.valueOf(dresult);
setDisplay(result);
op_flag = "";
break;
case "divide":
Rajasekaran S /AP/ IT
KGISL Institute of
Technology
op2 = data;
clearDisplay();
dop1 = Double.parseDouble(op1);
dop2 = Double.parseDouble(op2);
dresult = dop1 / dop2;
result = String.valueOf(dresult);
setDisplay(result);
op_flag = "";
break;
}
}
}
}
}
public class Main {
Rajasekaran S
/AP/ IT
KGISL Institute of Technology
Output:
Calculator:
Rajasekaran S /AP/ IT
KGISL Institute of Technology
Rajasekaran S /AP/ IT
KGISL Institute of Technology
Basic Operations
Rajasekaran S /AP/ IT
KGISL Institute of Technology
Rajasekaran S /AP/ IT
KGISL Institute of Technology
Multiplication [36 X 2]
Rajasekaran S /AP/ IT
KGISL Institute of Technology
Division [45 / 2]
Rajasekaran S /AP/ IT
KGISL Institute of Technology
Scientific Operations:
Sin 30
Rajasekaran S /AP/ IT
KGISL Institute of Technology
Cos 40:
Rajasekaran S /AP/ IT
KGISL Institute of Technology
Tan 23
Rajasekaran S /AP/ IT
KGISL Institute of Technology
Log 60
Rajasekaran S /AP/ IT
KGISL
Institute of Technology
Result:
The java GUI application for calculator with basic and advanced
functionalities was
developed and tested successfully.
Rajasekaran S /AP/ IT
KGISL Institute
of Technology
Important Links
S No Experiment Source Demo
https://github.com/
https://youtu.be/1uSOIZDz-
rajasekaranap/ AA
1 Electricity Bill Calculator
CS8383_Java_EB_Bill_Calc
ulator
https://github.com/ https://youtu.be/
Unit Converters Application
2 rajasekaranap/ 8HBADevR56M
using packages
CS8383_Java_Converters
https://github.com/ https://youtu.be/
rajasekaranap/ 8KuDnx8hxxQ
3 Employee Payroll System
CS8383_Java_Employee_Pa
yroll
https://github.com/ https://youtu.be/
Java Application for ADT
4 rajasekaranap/ KsWfHmRvDaU
Stack using Interfaces
CS8383_Java_StackADT
https://github.com/ https://youtu.be/-
Java Application for String
5 rajasekaranap/ 3Ge0TpVUvI
Operations using ArrayList
CS8383_Java_String_List
https://github.com/ https://youtu.be/
Java Application to Find the rajasekaranap/ mVI01UCZ1cw
6
Area of different Shapes CS8383_Java_Abstract_Are
a
https://github.com/ https://youtu.be/
Bank Transaction System rajasekaranap/ jknMYRQw-ac
7
with User Exceptions CS8383_Java_User_Excepti
on_Bank
https://github.com/ https://youtu.be/
Java Application for File rajasekaranap/ 9VhvcH3G4ws
8
Handling CS8383_Java_User_FileHan
dler
https://github.com/
https://youtu.be/1W8-
Java Application for Multi rajasekaranap/ ce1trPU
9
threading CS8383_Java_Multi_Thread
ing
https://github.com/ https://youtu.be/
Java Application for Generic
10 rajasekaranap/ L0KjoXi6FwM
Max Finder
CS8383_Java_Generic_Max
https://github.com/ https://youtu.be/
Calculator Application using rajasekaranap/ QQMWrG_NhFY
11
java AWT packages CS8383_Java_AWT_Calcul
ator_Advanced
Rajasekaran
S /AP/ IT
KGISL Institute of Technology
THANK YOU
Rajasekaran S /AP/ IT