OOP Lab Final Record
OOP Lab Final Record
NAME :
REGISTER NO :
ROLL NO : VM-
YEAR : II
SEMESTER : III
Vision
To emerge as centre for academic excellence in the field of Department Of Artificial Intelligence And Data Science
Mission
M1 - To provide good teaching and learning environment with conducive research atmosphere in the field of Computer
Science and Engineering.
M2 - To propagate lifelong learning.
M3 - To impart the right proportion of knowledge, attitudes and ethics in students to enable them take up positions of
responsibility in the society and make significant contributions.
An Autonomous Institution
CERTIFICATE
Name ……………………………………………………………………………………………………………………...
Year:…………………….Semester………………..Branch: B.Tech- Artificial Intelligence and Data Science
University Register No:………………………………………. College Roll No:VM-………………………… Certified that this is the
bonafide record of work done by the above student in the 191CS32B-OBJECT ORIENTED PROGRAMMING LABORATORY during
Signature of Examiners
The design techniques, analysis and the building, testing, operation and maintenance
PSO2 of networks, databases, security and computer systems (both hardware and
software).
An ability to identify, formulate and solve hardware and software problems using
PSO3
sound computer engineering principles.
GRADUATE ATTIRIBUTES (GAs)
GA’s
Engineering Knowledge: Apply knowledge of mathematics,
GA1 science, engineering fundamentals and an Engineering Specialization to the solution of complex
engineering problems.
Problem Analysis: Identify, formulate, review research literature and analyze complex
GA2 engineering problems reaching substantiated conclusions using first principles of mathematics,
natural sciences, and engineering sciences.
Design / Development of solutions: Design solutions for complex engineering problems and design
GA3 system components or processes that meet specified needs with appropriate consideration for public
health and safety, cultural, societal, and environmental considerations.
Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
GA5 engineering and IT tools including prediction and modeling to complex engineering activities with
an understanding of the limitations.
The Engineer and Society: Apply reasoning informed by the contextual knowledge to assess
GA6 societal, health, safety, legal and cultural issues and the consequent responsibilities relevant to the
professional engineering practice.
Environment and sustainability: Understand the impact of the professional engineering solutions
GA7 in societal and environmental contexts, and demonstrate the knowledge of, and need for
sustainable development.
Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of
GA8 the engineering practice.
Individual and team work: Function effectively as an individual, and as a member or leader in
GA9 diverse teams, and in multidisciplinary settings.
Project Management and Finance: Demonstrate knowledge and understanding of the engineering
GA11 and management principles and apply these to one’s own work, as a member and leader in a team, to
manage projects and in multidisciplinary environments.
Life-long learning: Recognize the need for, and have the preparation and ability to engage in
GA12 independent and life-long learning in the broadest context of technological change.
COURSE OBJECTIVES
➢ To build software development skills using java programming for real-world applications.
➢ To understand and apply the concepts of classes, packages, interfaces, arraylist, exception handling and file
processing.
➢ To develop applications using generic programming and event handling.
Course
Outcome
CO Statements
CO1 Configure various Java programs for simple applications that make use of classes,
packages and interfaces.
CO2 Design and deploy Java programs with array list, exception handling.
CO3 Learn how to design applications using file processing, generic programming and
event handling.
CO4 Develop and implement Java programs with and multithreading.
Implement the concepts of classes, packages, interfaces, array list, exception
CO5
handling and file processing.
Course
GA10
GA11
GA12
GA 1
GA 2
GA 3
GA 4
GA 5
GA 6
GA 7
GA 8
GA 9
PSO1
PSO2
PSO3
Outcome
CO1 3 2 2 1 1 1 - - - - - 2 3 2 2
CO2 3 2 2 1 1 1 - - - - - 1 3 2 2
CO3 3 2 2 1 1 1 1 - 1 - - 1 3 3 2
CO4 3 2 2 2 1 1 1 - - - - 2 3 2 2
CO5 3 2 1 1 1 1 - - 1 - - 2 2 2 2
CO 3 2 2 1 1 1 1 - 1 - - 2 2 2 2
1 – Low 2 – Medium 3 – High
Course Code: 191CS323
Course: OBJECT ORIENTED PROGRAMMING LABORATORY
COURSE PLAN
CO1,CO3
1 PROGRAM TO GENERATE ELECTRICITY BILL
5
PROGRAM TO PERFORM STRING OPERATIONS CO3,CO4
USING ARRAYLIST
PROGRAM TO CALCULATE AREA USING ABSTRACT
6 CO4
CLASS
PROGRAM TO IMPLEMENT USER DEFINED EXCEPTION
7 CO1,CO4
HANDLING
8 PROGRAM FOR DISPLAYING FILE INFORMATION CO5
AIM:
PROCEDURE :
1. Create a class with the following members Consumer no., consumer name, previous month reading, current month
reading, type of EB connection (i.e domestic or commercial)
2. Compute the bill amount using the following tariff. If the type of the EB connection is domestic, calculate the
amount to be paid as follows: First 100 units - Rs. 1 per unit 101-200 units - Rs. 2.50 per unit 201 -500 units -
Rs. 4 per unit > 501 units - Rs. 6 per unit If the type of the EB connection is commercial, calculate the amount to be
paid as follows: First 100 units - Rs. 2 per unit 101-200 units - Rs. 4.50 per unit 201 -500 units - Rs. 6 per unit
> 501 units - Rs. 7 per unit
3. Create the object for the created class .Invoke the methods to get the input from the consumer and display the
consumer information with the generated electricity bill.
Coding:
import java.util.*;
}}
double current,previous,tbill,units;
bn = in.nextInt();
System.out.print ("\n\t Enter Type of connection (D for Domestic or C for Commercial) ");
type = ins.nextLine();
cname = ins.nextLine();
current= in.nextDouble();
}
void calc()
units=current-previous;
if(type.equals("D"))
}}
void display()
}}
OUTPUT:
RESULT :
Thus the java program to generate electricity bill was implemented and executed successfully.
EX.NO: 2 PROGRAM TO IMPLEMENT CURRENCY CONVERTER, DISTANCE
DATE: CONVERTER AND TIME CONVERTER USING PACKAGES
AIM :
To develop a java application to implement currency converter ,distance converter and time converter using the
concept of packages .
PROCEDURE:
1. Create a Package currencyconversion and place the class currency under the package
2. Create the methods to perform currency conversion from dollar to rupee ,rupee to dollar,euro to rupee , rupee to
euro , yen to rupee and rupee to yen.
3. Create the package distanceconverion and create the class distance within the package
4. Create the methods to convert from meter to km, km to meter, miles to km,km to miles
5. Create the package timeconversion and create the class timer .Create the methods to convert from hours to minutes
,hours to seconds , minutes to hours and seconds to hours
6. Create a class and import the packages currencyconversion,distanceconversion and time conversion.Create the
objects for the class currency,distance and timer.
7. Get the choice from the user and invoke the methods to perform the corresponding conversion and display the
value.
CODING:
usd=in.nextInt(); inr=usd*67;
inr=in.nextInt(); usd=inr/67;
}
public void eurotorupee()
euro=in.nextInt();
inr=euro*79.50;
inr=in.nextInt();
euro=(inr/79.50);
yen=in.nextInt();
inr=yen*0.61;
inr=in.nextInt();
yen=(inr/0.61);
}}
import java.util.*;
System.out.print("Enter in km ");
km=sc.nextDouble();
m=(km*1000);
m=sc.nextDouble();
km=(m/1000);
System.out.print("Enter in miles");
miles=sc.nextDouble();
km=(miles*1.60934);
10 }
{ System.out.print("Enter in km");
km=sc.nextDouble();
miles=(km*0.621371);
}}
import java.util.*;
int input;
input = sc.nextInt();
minutes=sc.nextInt();
hours=minutes/60; minutes=minutes%60;
hours=sc.nextInt(); minutes=(hours*60);
hours=sc.nextInt(); seconds=(hours*3600);
}}
12 converter.java
import currencyconversion.*;
import distanceconversion.*;
System.out.println("10.kilometer to miles");
13 System.out.println("11.Hours to Minutes");
System.out.println("12.Hours to Seconds");
System.out.println("13.Seconds to Hours");
System.out.println("14.Minutes to Hours");
System.out.println("Enter ur choice");
choice=s.nextInt(); switch(choice)
case 1: { c.dollartorupee();
break;
case 2:
c.rupeetodollar();
break; }
case 3:
{ c.eurotorupee();
break;
}
case 4:
c.rupeetoeuro();
break;
14
case 5:
{c.yentorupee(); break;}
case 6 : { c.rupeetoyen();
break; }
case 7 :
{ d.mtokm();
break; }
case 8 :
{ d.kmtom();
break; }
case 9 :
{ d.milestokm();
break; }
case 10 : { d.kmtomiles();
15 break; }
case 11 : { t.hourstominutes();
break; }
case 12 :
{ t.hourstoseconds();
break; }
case 13 : { t.secondstohours();
break; }
case 14 :
{ t.minutestohours();
break; }
}
ch=s.nextInt(); }while(ch==1);
}
RESULT :
Thus the java application to implement currency converter ,distance converter and time converter
was implemented and executed successfully.
EX.NO: 3
PROGRAM TO GENERATE PAYSLIP USING INHERITANCE
DATE:
AIM:
To develop a java application to generate pay slip for different category of employees using the concept of
inheritance.
PROCEDURE:
1. Create the class employee with name, Empid, address, mailid, mobileno as members.
2. Inherit the classes programmer, asstprofessor,associateprofessor and professor from employee class.
3. Add Basic Pay (BP) as the member of all the inherited classes.
4. Calculate DA as 97% of BP, HRA as 10% of BP, PF as 12% of BP, Staff club fund as 0.1% of BP.
7.Create the objects for the inherited classes and invoke the necessary methods to display the Payslip.
CODING:
import java.util.*;
long mobile;
void getdata()
name = get.nextLine();
mailid = get.nextLine();
address = get.nextLine();
empid = get.nextInt();
mobile = get.nextLong();
}
void display()
System.out.println("Employee id : "+empid);
System.out.println("Mail id : "+mailid);
System.out.println("Address: "+address);
double salary,bp,da,hra,pf,club,net,gross;
void getprogrammer()
bp = get.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("Basic Pay:Rs"+bp);
System.out.println("DA:Rs"+da);
System.out.println("PF:Rs"+pf);
System.out.println("HRA:Rs"+hra);
System.out.println("CLUB:Rs"+club);
21 System.out.println("GROSS PAY:Rs"+gross);
System.out.println("NET PAY:Rs"+net);
}}
double salary,bp,da,hra,pf,club,net,gross;
void getasst()
bp = get.nextDouble();
} void calculateasst()
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("Basic Pay:Rs"+bp);
System.out.println("DA:Rs"+da);
System.out.println("HRA:Rs"+hra);
System.out.println("PF:Rs"+pf);
22 System.out.println("CLUB:Rs"+club);
System.out.println("GROSS PAY:Rs"+gross);
System.out.println("NET PAY:Rs"+net);
}}
double salary,bp,da,hra,pf,club,net,gross;
void getassociate()
bp = get.nextDouble();
} void calculateassociate()
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("Basic Pay:Rs"+bp);
System.out.println("DA:Rs"+da);
System.out.println("HRA:Rs"+hra);
System.out.println("PF:Rs"+pf);
23 System.out.println("CLUB:Rs"+club);
System.out.println("GROSS PAY:Rs"+gross);
System.out.println("NET PAY:Rs"+net);
}}
double salary,bp,da,hra,pf,club,net,gross;
void getprofessor()
bp = get.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("Basic Pay:Rs"+bp);
System.out.println("DA:Rs"+da);
System.out.println("HRA:Rs"+hra);
24 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
int choice,cont;
do
System.out.println("PAYROLL");
choice=c.nextInt(); switch(choice)
case 1:
{
p.getdata(); p.getprogrammer();
p.display(); p.calculateprog();
break;
25
asst.getdata();
asst.getasst();
asst.display();
asst.calculateasst();
break;
case 3:
asso.getdata();
asso.getassociate();
asso.display();
asso.calculateassociate();
break;
case 4:
prof.getdata();
prof.getprofessor();
prof.display();
prof.calculateprofessor();
break;
}
}
cont=c.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
PROGRAM FOR STACK ADT USING INTERFACE
DATE:
AIM:
To design a java application to implement array implementation of stack using the concept of interface and exception
handling.
PROCEDURE :
1. Create the interface stackoperation with method declarations for push and pop.
2. Create the class astack which implements the interface and provides implementation for the methods push and
pop.Also define the method for displaying the values stored in the stack.Handle the stack overflow and stack
underflow condition .
3. Create the class teststack .Get the choice from the user for the operation to be performed . and also handle the
exception that occur while performing the stack operation.
4. Create the object and invoke the method for push,pop,display based on the input from the user.
CODING:
import java.io.*;
if(top>=4)
System.out.println("overflow");
Else
top=top+1;
stack[top]=item;
System.out.println("item pushed"+stack[top]);
30 if(top<=top;i++)
System.out.println("element:"+stack[i]);
class teststack
int ch,c;
int i;
31 do
i=Integer.parseInt(in.readLine());
s.push(i);
break;
case 2:
s.pop();
break;
case 3:
break;
case 4:
break;
catch(IOException e)
System.out.println("io error");
c=Integer.parseInt(in.readLine());
while(c==1);
}
OUTPUT:
RESULT:
Thus the java application for stack operations has been implemented and executed successfully.
EX.NO: 5
PROGRAM TO PERFORM STRING OPERATIONS USING ARRAYLIST
DATE:
AIM:
To write a java program to perform string operations using ArrayList for the following functions a. Append - add at
end b. Insert – add at particular index c. Search d. List all string starts with given letter.
PROCEDURE:
1.Create the class arraylistexample. Create the object for the arraylist class.
3.Use the function add() to append the string at the end and to insert the string at the particular index.
4. The function sort () is used to sort the elements in the array list.
5. The function indexof() is used to search whether the element is in the array list or not.
6.The function startsWith () is used to find whether the element starts with the specified character.
7.The function remove() is used to remove the element from the arraylist.
8.The function size() is used to determine the number of elements in the array list
CODING:
import java.util.*;
import java.io.*;
String str,str1;
do
System.out.println("STRING MANIPULATION");
c=Integer.parseInt(in.readLine());
switch(c)
case 1:
str=in.readLine();
obj.add(str);
break;
case 2:
str=in.readLine();
i=Integer.parseInt(in.readLine());
obj.add(i-1,str);
break;
case 3:
str=in.readLine();
j=obj.indexOf(str);
if(j==-1)
else
System.out.println("Index of:"+str+"is"+j);
break;
}
case 4:
System.out.println("Enter the character to List string that starts with specified character");
str=in.readLine();
}}
OUTPUT:
RESULT:
Thus the java program to perform string operations using Array List has been implemented and executed
successfully.
EX.NO: 6
PROGRAM TO CALCULATE AREA USING ABSTRACT CLASS
DATE:
AIM:
To write a java program to calculate the area of rectangle,circle and triangle using the concept of abstract class.
PROCEDURE:
1. Create an abstract class named shape that contains two integers and an empty method named printarea().
2. Provide three classes named rectangle, triangle and circle such that each one of the classes extends the class Shape.
3.Each of the inherited class from shape class should provide the implementation for the method printarea().
4.Get the input and calculate the area of rectangle,circle and triangle .
5. In the shapeclass , create the objects for the three inherited classes and invoke the methods and display the area
values of the different shapes.
CODING:
import java.util.*;
a=s.nextInt();
b=s.nextInt();
area_rect=a*b;
{
double area_tri;
a=s.nextInt();
b=s.nextInt();
area_tri=(0.5*a*b);
a=s.nextInt();
area_circle=(3.14*a*a);
System.out.println("Radius of circle"+a);
r.printarea();
t.printarea();
circle r1=new circle();
r1.printarea();
OUTPUT:
RESULT:
Thus a java program for calculate the area of rectangle,circle and triangle was implemented and executed
successfully.
EX.NO: 7
PROGRAM TO IMPLEMENT USER DEFINED EXCEPTION HANDLING
DATE:
AIM:
PROCEDURE:
5.Using the exception handling mechanism , the thrown exception is handled by the catch construct.
6.After the exception is handled , the string “invalid amount “ will be displayed.
7.If the amount is greater than 0 , the message “Amount Deposited “ will be displayed.
(a)CODING:
import java.util.Scanner;
String msg;
NegativeAmtException(String msg)
this.msg=msg;
return msg;
{
Scanner s=new Scanner(System.in);
System.out.print("Enter Amount:");
int a=s.nextInt();
OUTPUT:
(b)CODING:
String str1;
MyException(String str2)
str1=str2;
class example
try
{
catch(MyException exp)
System.out.println("Catch Block") ;
System.out.println(exp) ;
OUTPUT:
RESULT:
Thus a java program to implement user defined exception handling has been implemented and executed
successfully.
EX.NO: 8
PROGRAM FOR DISPLAYING FILE INFORMATION
DATE:
AIM:
To write a java program that reads a file name from the user, displays information about whether the file exists,
whether the file is readable, or writable, the type of file and the length of the file in bytes.
PROCEDURE:
1.Create a class filedemo. Get the file name from the user .
2.Use the file functions and display the information about the file.
5.getParent () -This method returns the pathname string of this abstract pathname’s parent, or null if this pathname
does not name a parent directory.
14.Invoke the predefined functions abd display the iformation about the file.
CODING:
import java.io.*;
import java.util.*;
String filename;
System.out.println("*****************");
System.out.println("FILE INFORMATION");
System.out.println("*****************");
System.out.println("PARENT"+f1.getParent());
if(f1.exists())
else
if(f1.canRead())
if(f1.canWrite())
else
if(f1.isDirectory())
Else
System.out.println("NOT A DIRECTORY");
RESULT:
Thus a java program to display file information has been implemented and executed successfully
EX.NO: 9
PROGRAM TO IMPLEMENT MULTITHREADED APPLICATION
DATE:
AIM:
PROCEDURE:
1.Create a class even which implements first thread that computes .the square of the number .
2. run() method implements the code to be executed when thread gets executed.
3.Create a class odd which implements second thread that computes the cube of the number.
4.Create a third thread that generates random number. If the random number is even , it displays the square of the
number. If the random number generated is odd, it displays the cube of the given number .
5.The Multithreading is performed and the task switched between multiple threads.
6.The sleep () method makes the thread to suspend for the specified time.
CODING:
import java.util.*;
this.x = x;
System.out.println("New Thread "+ x +" is EVEN and Square of " + x + " is: " + x * x);
public int x;
{
System.out.println("New Thread "+ x +" is ODD and Cube of " + x + " is: " + x * x * x);
int num = 0;
try
num = r.nextInt(100);
if (num % 2 == 0)
t1.start();
Else
t2.start(); } Thread.sleep(1000);
System.out.println(" ");
System.out.println(ex.getMessage());
}
}
RESULT:
Thus a java program for multi-threaded application has been implemented and executed successfully
EX.NO: 10 PROGRAM TO FIND THE MAXIMUM VALUE FROM THE GIVEN TYPE OF
DATE: ELEMENTS USING GENERICS
AIM:
To write a java program to find the maximum value from the given type of elements using a generic function.
PROCEDURE:
3.Create the objects of the class to hold integer, character and double values.
4.Create the method to compare the values and find the maximum value stored in the array.
5.Invoke the method with integer, character or double values . The output will be displayed based on the data type
passed to the method.
CODING:
class MyClass>
T[] vals;
MyClass(T[] o) { vals = o;
public T min()
T v = vals[0];
if(vals[i].compareTo(v) < 0)
v = vals[i]; return v;
public T max()
T v = vals[0];
return v;
}
class gendemo
int i;
Integer inums[]={10,2,5,4,6,1};
Character chs[]={'v','p','s','a','n','h'};
Double d[]={20.2,45.4,71.6,88.3,54.6,10.4};
}}
RESULT :
Thus a java program to find the maximum value from the given type of elements has been implemented
using generics and executed successfully
EX.NO: 11 PROGRAM TO DESIGN A CALCULATOR USING EVENT DRIVEN
DATE: PROGRAMMING PARADIGM OF JAVA
AIM:
To design a calculator using event driven programming paradigm of Java with the following options a) Decimal
Manipulations b) Scientific Manipulations.
PROCEDURE:
3. Create the container and add controls for digits , scientific calculations and decimal Manipulations.
5.When the user presses the control , the event is generated and handled .
CODING:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
JTextField tfield;
int k = 1, x = 0, y = 0, z = 0;
char ch;
JButton b1, b2, b3, b4, b5, b6, b7, b8, b9, zero, clr, pow2, pow3, exp, fac, plus, min, div, log, rec, mul, eq, addSub,
dot, mr, mc, mp, mm, sqrt, sin, cos, tan;
Container cont;
tfield.setHorizontalAlignment(SwingConstants.RIGHT);
tfield.addKeyListener(new KeyAdapter()
{
66 char c = keyevent.getKeyChar();
textpanel.add(tfield);
buttonpanel.add(mr);
mr.addActionListener(this);
mc = new JButton("MC");
buttonpanel.add(mc);
mc.addActionListener(this);
mp = new JButton("M+");
buttonpanel.add(mp);
mp.addActionListener(this);
mm = new JButton("M-");
buttonpanel.add(mm);
mm.addActionListener(this);
b1 = new JButton("1");
buttonpanel.add(b1);
67 b1.addActionListener(this);
b2 = new JButton("2");
buttonpanel.add(b2);
b2.addActionListener(this);
b3 = new JButton("3");
buttonpanel.add(b3);
b3.addActionListener(this);
b4 = new JButton("4");
buttonpanel.add(b4);
b4.addActionListener(this);
b5 = new JButton("5");
buttonpanel.add(b5);
b5.addActionListener(this);
b6 = new JButton("6");
buttonpanel.add(b6);
b6.addActionListener(this);
b7 = new JButton("7");
buttonpanel.add(b7);
b7.addActionListener(this);
b8 = new JButton("8");
buttonpanel.add(b8);
b8.addActionListener(this);
b9 = new JButton("9");
buttonpanel.add(b9);
b9.addActionListener(this);
buttonpanel.add(zero);
68 zero.addActionListener(this);
buttonpanel.add(plus);
plus.addActionListener(this);
buttonpanel.add(min);
min.addActionListener(this);
buttonpanel.add(mul);
mul.addActionListener(this);
div.addActionListener(this);
buttonpanel.add(div);
buttonpanel.add(addSub);
addSub.addActionListener(this);
buttonpanel.add(dot);
dot.addActionListener(this);
eq = new JButton("=");
buttonpanel.add(eq);
eq.addActionListener(this);
buttonpanel.add(rec);
rec.addActionListener(this);
buttonpanel.add(sqrt);
69 sqrt.addActionListener(this);
buttonpanel.add(log);
log.addActionListener(this);
buttonpanel.add(sin);
sin.addActionListener(this);
buttonpanel.add(cos);
cos.addActionListener(this);
buttonpanel.add(tan);
tan.addActionListener(this);
buttonpanel.add(pow2);
pow2.addActionListener(this);
pow3.addActionListener(this);
exp.addActionListener(this);
buttonpanel.add(exp);
fac.addActionListener(this);
buttonpanel.add(fac);
buttonpanel.add(clr);
70 clr.addActionListener(this);
cont.add("Center", buttonpanel);
cont.add("North", textpanel);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
String s = e.getActionCommand();
if (s.equals("1"))
{ if (z == 0) {
tfield.setText(tfield.getText() + "1");
Else
tfield.setText("");
tfield.setText(tfield.getText() + "1"); z = 0;
if (s.equals("2"))
{ if (z == 0)
tfield.setText(tfield.getText() + "2");
}
else
71 tfield.setText("");
tfield.setText(tfield.getText() + "2"); z = 0;
if (s.equals("3")) { if (z == 0)
tfield.setText(tfield.getText() + "3");
Else
{ tfield.setText("");
tfield.setText(tfield.getText() + "3");
z = 0; }}
if (s.equals("4"))
{ if (z == 0)
{ tfield.setText(tfield.getText() + "4"); }
else
{ tfield.setText("");
tfield.setText(tfield.getText() + "4"); z = 0; }}
72 if (s.equals("5"))
{ if (z == 0)
tfield.setText(tfield.getText() + "5");
else
tfield.setText("");
tfield.setText(tfield.getText() + "5");
z = 0; }}
if (s.equals("6"))
{
if (z == 0)
tfield.setText(tfield.getText() + "6");
Else
{ tfield.setText("");
tfield.setText(tfield.getText() + "6"); z = 0; }}
if (s.equals("7"))
if (z == 0)
tfield.setText(tfield.getText() + "7");
else 73 { tfield.setText("");
tfield.setText(tfield.getText() + "7");
z = 0;
}}
if (s.equals("8"))
{ if (z == 0)
tfield.setText(tfield.getText() + "8");
Else
tfield.setText("");
tfield.setText(tfield.getText() + "8");
z = 0; }} if (s.equals("9"))
{ if (z == 0)
{ tfield.setText(tfield.getText() + "9");
else { tfield.setText("");
tfield.setText(tfield.getText() + "9");
z = 0; } 74 } if (s.equals("0"))
{ if (z == 0)
tfield.setText(tfield.getText() + "0");
else
tfield.setText("");
tfield.setText(tfield.getText() + "0");
z = 0;
}}
if (s.equals("AC")) { tfield.setText("");
x = 0; y = 0; z = 0;
if (s.equals("log"))
if (tfield.getText().equals(""))
tfield.setText("");
else {
a = Math.log(Double.parseDouble(tfield.getText()));
75 tfield.setText("");
tfield.setText(tfield.getText() + a);
}}
if (s.equals("1/x")) { if (tfield.getText().equals(""))
tfield.setText("");
Else
a = 1 / Double.parseDouble(tfield.getText());
tfield.setText("");
tfield.setText(tfield.getText() + a);
if (s.equals("Exp"))
if (tfield.getText().equals(""))
tfield.setText("");
else
a = Math.exp(Double.parseDouble(tfield.getText()));
tfield.setText("");
tfield.setText(tfield.getText() + a);
if (s.equals("x^2"))
76 if (tfield.getText().equals(""))
tfield.setText("");
} else
if (s.equals("x^3"))
if (tfield.getText().equals(""))
tfield.setText("");
else
{
a = Math.pow(Double.parseDouble(tfield.getText()), 3);
tfield.setText("");
tfield.setText(tfield.getText() + a);
if (s.equals("+/-")) { if (x == 0)
tfield.setText("-" + tfield.getText()); x = 1;
else 77 { tfield.setText(tfield.getText());
if (s.equals(".")) { if (y == 0)
tfield.setText(tfield.getText() + ".");
y = 1;
else { tfield.setText(tfield.getText());
if (s.equals("+"))
if (tfield.getText().equals(""))
Else
temp = Double.parseDouble(tfield.getText());
tfield.setText("");
ch = '+';
78 y = 0;
x = 0;
tfield.requestFocus();
if (s.equals("-"))
if (tfield.getText().equals(""))
tfield.setText("");
temp = 0; ch = '-';
else
x = 0; y = 0; temp = Double.parseDouble(tfield.getText());
tfield.setText("");
ch = '-';
tfield.requestFocus();
if (s.equals("/"))
if (tfield.getText().equals(""))
tfield.setText("");
79 temp = 1;
ch = '/';
Else
x = 0; y = 0; temp = Double.parseDouble(tfield.getText());
ch = '/'; tfield.setText("");
}
tfield.requestFocus();
if (s.equals("*"))
if (tfield.getText().equals(""))
tfield.setText("");
temp = 1; ch = '*';
} else
{ x = 0; y = 0;
temp = Double.parseDouble(tfield.getText());
ch = '*'; tfield.setText("");
80 }
tfield.requestFocus();
if (s.equals("MC"))
m1 = 0; tfield.setText(""); }
if (s.equals("MR")) { tfield.setText("");
tfield.setText(tfield.getText() + m1);
} if (s.equals("M+"))
{ if (k == 1) { m1 = Double.parseDouble(tfield.getText()); k++;
else
else
m1 -= Double.parseDouble(tfield.getText());
tfield.setText("" + m1); } }
if (s.equals("Sqrt")) {
if (tfield.getText().equals(""))
tfield.setText("");
else
a = Math.sqrt(Double.parseDouble(tfield.getText()));
tfield.setText("");
field.setText(tfield.getText() + a);
}}
if (s.equals("SIN"))
if (tfield.getText().equals(""))
82 tfield.setText("");
else
a = Math.sin(Double.parseDouble(tfield.getText()));
tfield.setText("");
tfield.setText(tfield.getText() + a);
if (s.equals("COS")) { if (tfield.getText().equals(""))
{ tfield.setText(""); }
else { a = Math.cos(Double.parseDouble(tfield.getText()));
tfield.setText("");
tfield.setText(tfield.getText() + a);
}}
if (s.equals("TAN"))
{ if (tfield.getText().equals(""))
{ tfield.setText(""); }
else 83
a = Math.tan(Double.parseDouble(tfield.getText()));
tfield.setText("");
tfield.setText(tfield.getText() + a);
}}
if (s.equals("="))
{ if (tfield.getText().equals(""))
tfield.setText(""); }
else
temp1 = Double.parseDouble(tfield.getText());
switch (ch)
break;
case '-':
break;
case '/':
break;
case '*':
break;
tfield.setText("");
tfield.setText(tfield.getText() + result); z = 1;
}
}
if (s.equals("n!"))
if (tfield.getText().equals(""))
tfield.setText("");
Else
a = fact(Double.parseDouble(tfield.getText())); tfield.setText("");
tfield.setText(tfield.getText() + a);
tfield.requestFocus();
double fact(double x)
int er = 0; if (x < 0) 85
{ er = 20;
return 0;
double i, s = 1;
try
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
catch (Exception e)
{}
ScientificCalculator f = new ScientificCalculator();
f.setTitle("ScientificCalculator");
f.pack();
f.setVisible(true);
}}
RESULT:
Thus the java programs for scientific calculator has been implemented and executed successfully