List of Experiments: CS8382 Object Oriented Programming Laboratory LTPC 0 0 4 2
List of Experiments: CS8382 Object Oriented Programming Laboratory LTPC 0 0 4 2
0042
COURSE OBJECTIVES
List of experiments
1. Develop a Java application to generate Electricity bill. 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). 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
01-200 units - Rs. 4.50 per unit
201 -500 units - Rs. 6 per unit
>501 units - Rs. 7 per unit
3. 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
4. Design a Java interface for ADT Stack. Implement this interface using array.
Provide necessary exception handling in both the implementations.
2
5. Write a program to perform string operations using ArrayList. Write functions for
the following
a. Append - add at end
b. Insert – add at particular index
c. Search
d. List all string starts with given letter
6. Write a Java Program to create an abstract class named Shape 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 extends the class Shape. Each one of
the classes contains only the method print Area () that prints the area of the given shape.
8. 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.
9. 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.
10. Write a java program to find the maximum value from the given type of elements using
a generic function.
11. Design a calculator using event-driven programming paradigm of Java with the
following options.
a) Decimal manipulations
b) Scientific manipulations
12. Develop a mini project for any application using Java concepts.
TOTAL : 60 PERIODS
COURSE OUTCOMES
Upon completion of the course, the students will be able to
1. Develop and implement Java programs for simple applications that make use of
classes, packages and interfaces.
2. Develop and implement Java programs with arraylist, exception handling
and multithreading
.
3. Design applications using file processing, generic programming and event handling.
3
LIST OF EXPERIMENTS
S. No Experiment Name Signature
4
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
COURSE PLAN
Regulation – 2017
S. No. of CO
Topics
No. hours Mapping
1. Simple Java Programs Practice 8 CO1
2. Develop a java application to generate Electricity bill 8 CO1
Develop a java application to implement currency converter using 4 CO2
3.
packages
Develop a java application to generate pay slips for the employees 4 CO2
4. with their gross and net salary
Design a java interface for ADT Stack and Array with necessary 4 CO3
5.
exception
Develop a java program to perform string operations using Array 4 CO3
6.
List.
7. Write a java Program to create an abstract class 4 CO3
8. Write a java program to implement user defined exception handling 4 CO3
9. Develop a java program to implement file operation(read & write) 4 CO3
10. Write a java program that implements a multi-threaded application 4 CO4
Write a java program to find maximum value from given elements 4 CO4
11.
using generic function
Design a Decimal and Scientific calculator using event-driven 8 CO5
12.
programming in java.
Total Hours 60
5
EXPT: 1 APPLICATION TO GENERATE ELECTRICITY BILL
DATE:
AIM:
ALGORITHM:
PROGRAM:
import java.io.*;
importjava.util.*;
public class EBbillCalculation
{
intcno;
String cname;
intpm_reading,cm_reading,units;
doublebillpay;
voidgetdetails()
{
Scanner in = new Scanner(System.in);
System.out.println("Enter the Consumer No:");
cno=in.nextInt();
System.out.println("Enter the Consumer Name:");
cname=in.next();
System.out.println("Enter the Previous Month Reading:");
pm_reading=in.nextInt();
System.out.println("Enter the Current Month Reading:");
cm_reading=in.nextInt();
units=cm_reading-pm_reading;
System.out.println("Choose the type of EB Connection
1. Domestic connection 2. Commercial
connection");
intch=in.nextInt();
switch(ch)
{
6
case 1:
Domestic_Calculation(units);
break;
7
case 2: Commercial_Calculation(units);
break;
}
}
voidDomestic_Calculation(int units)
{
billpay = 0;
if(units<=100)
{
billpay=units*1.00;
}
else if(units>100 && units<=200)
{
billpay=100*1.00+(units-100)*2.50;
}
else if(units>200 && units<=500)
{
billpay=100*1.00+200*2.50+(units-200)*4.00;
}
else if(units>500)
{
billpay =100*1.00+200*2.50+500*4.00+(units-
500)*6.00;
}
show();
System.out.println("Amount to be Paid : " + billpay);
}
voidCommercial_Calculation(int units)
{
billpay = 0;
if(units<=100)
{
billpay=units*2.00;
}
else if(units>100 && units<=200)
{
billpay=100*2.00+(units-100)*4.50;
}
8
billpay =100*2.00+200*4.50+500*6.00+(units-500)*7.00;
}
show();
System.out.println("Amount to be Paid : " + billpay);
}
9
OUTPUT:
RESULT:
Thus the java application for generating the electricity bill is created and
executed successfully.
10
EXPT: 2 a) CURRENCY CONVERTER
DATE:
AIM:
ALGORITHM:
PROGRAM:
packagecurrencyconverter;
import java.io.*;
importjava.util.Scanner;
doubleRs;
Scanner in = new Scanner(System.in);
System.out.println("Choose the type of currency conversition");
System.out.println("1.USDollar to INDRupees,2.Euro to
INDRupees,3. JapaneseYen to INDRupees");
intch=in.nextInt();
switch(ch)
{
case 1: System.out.println("Dollar to Rupees
conversion"); System.out.println("Enter the
number of Dollars");
11
double dollar=in.nextInt();
Rs=dollar*67.02;
System.out.println("USD="+dollar+" is INR="+Rs);
break;
case 2: System.out.println("EURO to Rupees
conversion"); System.out.println("Enter the
number of EURO"); double Euro=in.nextInt();
Rs=Euro*78.29;
System.out.println("Euro="+Euro+" is INR="+Rs);
break;
case 3: System.out.println("Japanese Yen to Rupees
conversion"); System.out.println("Enter the number of
Yen");
double Yen=in.nextInt();
Rs=Yen*0.61;
System.out.println("Yen="+Yen+" is INR="+Rs);
break;
}
}
}
12
OUTPUT:
RESULT:
13
EXPT: 2 b) DISTANCE CONVERTER
DATE:
AIM:
ALGORITHM:
PROGRAM:
packagecurrencyconverter;
import java.io.*;
importjava.util.Scanner;
public class distanceconvertor
{ public static void main(String
args[])
{
doublemeters,kilometers,miles;
Scanner in = new Scanner(System.in);
15
case 2: System.out.println("Miles to Kilometers
conversion"); System.out.println("Enter the number
of Miles"); miles=in.nextDouble();
kilometers =miles * 1.60934;
System.out.println( miles+ " Miles is " +kilometers + " in
Kilometers");
break;
}
}
}
16
OUTPUT:
RESULT:
DATE:
AIM:
ALGORITHM:
PROGRAM:
packagecurrencyconverter;
importjava.util.Scanner;
OUTPUT:
RESULT:
AIM:
ALGORITHM:
PROGRAM:
package employee;
importjava.io.IOException;
importjava.util.Scanner;
classEmp
{
String ename,Address,email;
inteid;
int mobile;
voidgetEmployeedetails()
{
Scanner in = new Scanner(System.in);
System.out.println("Enter the Emp_id. :");
eid=in.nextInt();
System.out.println("Enter the Employee Name:");
ename=in.next();
System.out.println("Enter the Employee Address:");
Address=in.next();
System.out.println("Enter the Employee Email id :");
email=in.next();
System.out.println("Enter the Mobile No:");
mobile=in.nextInt();
}
voidpay_calulation(double BasicPay)
{
doubleDA,HRA,PF,Sfund,Gross_Salary,Netsalary;
DA=BasicPay*0.97;
HRA=BasicPay*0.10;
PF=BasicPay*0.12;
Sfund=BasicPay*0.1;
Gross_Salary=BasicPay+DA+HRA;
Netsalary=Gross_Salary-(PF+Sfund);
System.out.println("Gross salary of the Employee"+Gross_Salary);
System.out.println("Net salary of the Employee: "+Netsalary);
}
void display()
{
System.out.println("Emp_id:"+eid);
System.out.println("Employee Name:"+ename);
System.out.println("Employee Address:"+Address);
System.out.println("Employee Email id :"+email);
System.out.println("Employee Mobile No:"+mobile);
}
}
class Programmer extends Emp
{
doubleBasicPay;
voidProgrammerdetails()
{
getEmployeedetails();
Scanner in = new Scanner(System.in);
System.out.println("Enter the Basic Pay of the Programmer:");
BasicPay=in.nextInt();
display();
pay_calulation(BasicPay);
}
}
classAssistantProfessor extends Emp
{
voidAPDetails()
{
doubleBasicPay;
getEmployeedetails();
Scanner in = new Scanner(System.in);
System.out.println("Enter the Basic Pay of the AssistantProfessor:");
BasicPay=in.nextInt();
display();
pay_calulation(BasicPay);
}
}
classAssociateProfessor extends Emp
{
doubleBasicPay;
voidASPDetails()
{
getEmployeedetails();
Scanner in = new Scanner(System.in);
System.out.println("Enter the Basic Pay of the AssociateProfessor:");
BasicPay=in.nextInt();
display();
pay_calulation(BasicPay);
}
}
class Professor extends Emp
{
doubleBasicPay;
voidprofDetails()
{
getEmployeedetails();
Scanner in = new Scanner(System.in);
System.out.println("Enter the Basic Pay of the Professor:");
BasicPay=in.nextInt();
display();
pay_calulation(BasicPay);
}
}
}}
OUTPUT:
RESULT:
Thus the java program for generating the employee pay slip is created
and executed successfully.
EXPT: 4 ADT STACK
DATE:
AIM:
ALGORITHM:
PROGRAM:
packagestackadt;
import java.io.*;
interfaceMystack
{
public void pop();
public void push();
public void display();
}
classStack_array implements Mystack
{
final static int n=5;
int stack[]=new int[n];
int top=-1;
public void push()
{
try
{
BufferedReaderbr=new BufferedReader(new
InputStreamReader(System.in));
if(top==(n-1))
{
System.out.println(" Stack Overflow");
return;
}
else
{
System.out.println("Enter the element");
intele=Integer.parseInt(br.readLine());
stack[++top]=ele;
}
}
catch(IOException e)
{
System.out.println("e");
}
}
public void pop()
{
if(top<0)
{
System.out.println("Stack underflow");
return;
}
else
{
int
popper=stack[top];
top--;
System.out.println("Popped element:" +popper);
}
}
RESULT:
Thus the program for program using Java interface for ADT Stack has
been written and executed successfully.
EXPT: 5 ARRAY LIST
DATE:
AIM:
ALGORITHM:
Step 5: Append the arrlist2 to the end of arrlist Using addAll() method .
Step 7: Print all string starts with given letter by using matches() method.
PROGRAM:
importjava.util.ArrayList;
importjava.util.Scanner;
RESULT:
Thus the program for Arraylist has been written and executed
successfully.
EXPT NO: 6 ABSTRACT CLASS
DATE:
AIM:
ALGORITHM:
PROGRAM:
package javaapplication3;
abstract class shape
{
int a=3,b=4;
abstract public void print_area();
}
class rectangle extends shape
{
publicintarea_rect;
@Override
public void print_area()
{
area_rect=a*b;
System.out.println("The area ofrectangle is:"+area_rect);
}
}
class triangle extends shape
{
intarea_tri;
@Override
public void print_area()
{
area_tri=(int) (0.5*a*b);
System.out.println("The area oftriangle is:"+area_tri);
}
}
class circle extends shape
{
intarea_circle;
@Override
public void print_area()
{
area_circle=(int) (3.14*a*a);
System.out.println("The area ofcircle is:"+area_circle);
}
}
public class JavaApplication3 {
public static void main(String[] args) {
rectangle r=new rectangle();
r.print_area();
triangle t=new triangle();
t.print_area();
circle r1=new circle();
r1.print_area();
}
}
OUTPUT:
RESULT:
Thus the program for abstract class has been written and executed
successfully.
EXPT: 7 USER DEFINED EXCEPTION HANDLING
DATE:
AIM:
ALGORITHM:
PROGRAM:
package example1;
OUTPUT:
RESULT:
Thus the program user defined exception handling has been written and
executed successfully.
EXPT: 8 FILE OPERATIONS
DATE:
AIM:
ALGORITHM:
PROGRAM:
importjava.util.Scanner;
importjava.io.File;
OUTPUT:
Fib.java
for(i=2;i<count;++i)
{
n3=n1+n2;
System.out.print(" "+n3);
n1=n2;
n2=n3;
}
}
}
RESULT:
Thus the program for implementing the file concept has been written and
executed successfully.
EXPT: 9 MULTI THREADING
DATE:
AIM:
ALGORITHM:
PROGRAM:
packagemtherad;
importjava.util.*;
@Override
public void run()
{
System.out.println("Thread Name:Even Thread and square is: " + x * x);
}
class A extends Thread{
public String tname;
public Random r;
public Thread
t1,t2; public
A(String s)
{ tname=s;
}
@Override
public void run()
{
intnum=0;
r=new Random();
try {
for(int i=0;i<50;i++){
num=r.nextInt(100);
System.out.println("main thread and generated number is"+num);
if(num%2==0)
{
t1=new Thread(new even(num));
t1.start();
}else{
t2=new Thread(new odd(num));
t2.start();
}
Thread.sleep(1000);
System.out.println("-----------------------------------");
}
}
catch(InterruptedException ex)
{
System.out.println(ex.getMessage());
}
}
}
public class Mtherad {
}
OUTPUT:
RESULT:
AIM:
ALGORITHM:
PROGRAM:
packagegenericmethodtest;
if(z.compareTo(max) > 0)
{ max = z;// z is the largest
now
}
return max; // returns the largest object
}
}
}
OUTPUT:
RESULT:
Thus the program for finding the maximum value using generic function
has been written and executed successfully.
EXPT: 11 CALCULATOR
DATE:
AIM:
ALGORITHM:
PROGRAM:
importjava.awt.*;
importjavax.swing.*;
importjava.awt.event.*;
importjavax.swing.event.*;
public class ScientificCalculator extends JFrame implements
ActionListener
{
JTextFieldtfield;
double temp,temp1,result,a,ml;
static double m1,m2;
int k=1,x=0,y=0,z=0;
charch;
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;
JPaneltextpanel,buttonpanel;
ScientificCalculator()
{
cont=getContentPane();
cont.setLayout(new BorderLayout());
JPaneltextpanel=new JPanel();
tfield=new JTextField(25);
tfield.setHorizontalAlignment(SwingConstants.RIGHT);
tfield.addKeyListener(new KeyAdapter()
{
public void keyTyped(KeyEventkeyevent)
{
char c=keyevent.getKeyChar();
if(c>='0'&&c<='9')
{
}
else
{
keyevent.consume();
}
}
});
textpanel.add(tfield);
buttonpanel=new JPanel();
buttonpanel.setLayout(new GridLayout(8,4,2,2));
boolean t=true;
mr=new JButton("MR");
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);
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);
zero=new JButton("0");
buttonpanel.add(zero);
zero.addActionListener(this);
plus=new JButton("+");
buttonpanel.add(plus);
plus.addActionListener(this);
min=new JButton("-");
buttonpanel.add(min);
min.addActionListener(this);
mul=new JButton("*");
buttonpanel.add(mul);
mul.addActionListener(this);
div=new JButton("/");
buttonpanel.add(div);
div.addActionListener(this);
addsub=new JButton("+/-");
buttonpanel.add(addsub);
addsub.addActionListener(this);
dot=new JButton(".");
buttonpanel.add(dot);
dot.addActionListener(this);
eq=new JButton("=");
buttonpanel.add(eq);
eq.addActionListener(this);
rec=new JButton("1/x");
buttonpanel.add(rec);
rec.addActionListener(this);
sqrt=new JButton("Sqrt");
buttonpanel.add(sqrt);
sqrt.addActionListener(this);
log=new JButton("log");
buttonpanel.add(log);
log.addActionListener(this);
sin=new JButton("SIN");
buttonpanel.add(sin);
sin.addActionListener(this);
cos=new JButton("COS");
buttonpanel.add(cos);
cos.addActionListener(this);
tan=new JButton("TAN");
buttonpanel.add(tan);
tan.addActionListener(this);
pow2=new JButton("x^2");
buttonpanel.add(pow2);
pow2.addActionListener(this);
pow3=new JButton("X^3");
buttonpanel.add(pow3);
pow3.addActionListener(this);
exp=new JButton("Exp");
buttonpanel.add(exp);
exp.addActionListener(this);
fac=new JButton("n!");
buttonpanel.add(fac);
fac.addActionListener(this);
clr=new JButton("AC");
buttonpanel.add(clr);
clr.addActionListener(this);
cont.add("Center",buttonpanel);
cont.add("North",textpanel);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e)
{
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
{
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;
}
}
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
{
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;
}
}
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()));
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"))
{
if(tfield.getText().equals(""))
{
tfield.setText("");
}
else
{
a=Math.pow(Double.parseDouble(tfield.getText()),2);
tfield.setText("");
tfield.setText(tfield.getText()+a);
}
}
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
{
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(""))
{
tfield.setText("");
temp=0;
ch='+';
}
else
{
temp=Double.parseDouble(tfield.getText());
tfield.setText("");
ch='+';
y=0;x=0;
}
tfield.requestFocus();
}
if(s.equals("-"))
{
if(tfield.getText().equals(""))
{
tfield.setText("");
temp=0;
ch='-';
}
else
{
y=0;x=0;
temp=Double.parseDouble(tfield.getText());
tfield.setText("");
ch='-';
}
tfield.requestFocus();
}
if(s.equals("/"))
{
if(tfield.getText().equals(""))
{
tfield.setText("");
temp=1;
ch='/';
}
else
{
y=0;x=0;
temp=Double.parseDouble(tfield.getText());
ch='/';
tfield.setText("");
}
tfield.requestFocus();
}
if(s.equals("*"))
{
if(tfield.getText().equals(""))
{
tfield.setText("");
temp=1;
ch='*';
}
else
{
y=0;x=0;
temp=Double.parseDouble(tfield.getText());
ch='*';
tfield.setText("");
}
tfield.requestFocus();
}
if(s.equals("MC"))
{
ml=0;
tfield.setText("");
}
if(s.equals("MR"))
{
tfield.setText("");
tfield.setText(tfield.getText()+ml);
}
if(s.equals("M+"))
{
if(k==1)
{
ml=Double.parseDouble(tfield.getText());
k++;
}
else
{
ml+=Double.parseDouble(tfield.getText());
tfield.setText(""+ml);
}
}
if(s.equals("M-"))
{
if(k==1)
{
ml=Double.parseDouble(tfield.getText());
k++;
}
else
{
ml-=Double.parseDouble(tfield.getText());
tfield.setText(""+ml);
}
}
if(s.equals("Sqrt"))
{
if(tfield.getText().equals(""))
{
tfield.setText("");
}
else
{
a=Math.sqrt(Double.parseDouble(tfield.getText()));
tfield.setText("");
tfield.setText(tfield.getText()+a);
}
}
if(s.equals("SIN"))
{
if(tfield.getText().equals(""))
{
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
{
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)
{
case '+':
result=temp+temp1;
break;
case '-':
result=temp-temp1;
break;
case '/':
result=temp/temp1;
break;
case '*':
result=temp*temp1;
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)
{
/*inter=0;
if(x>0)
{
er=20;
return 0;
}*/
doublei,s=1;
for(i=2;i<=x;i+=1.0)
s*=i;
return s;
}
public static void main(String srgs[])
{
/*try
{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.Window
sLookAndFeel");
}
catch(Exception e)
{
/*/ ScientificCalculator f;
f=new ScientificCalculator();
f.setTitle("Scientific calculator");
f.pack();
f.setVisible(true);
/* } */
}
}
OUTPUT:
RESULT:
Thus the calculator program has been written and executed successfully.
EXPT: 12 MINIPROJECT (ONLINE QUIZ
SYSTEM) DATE:
OBJECTIVE:
1. Teacher
2. Student
Functional Requirements
1. Teacher
2. Student
Non-Functional Requirements
Tools to be used
SOURCE PACKAGE:
packagecom.javatpoint;
importjavax.servlet.*;
importjava.sql.*;
contextInitialized(ServletContextEvent arg0) {
Connection con=null;
try{
ResultSetrs;
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe
","system","oracle");
PreparedStatement ps2= con.prepareStatement("CREATE
SEQUENCE JAVATPOINT MINVALUE 1 MAXVALUE 999999999
INCREMENT BY 1 START WITH 1 NOCACHE NOORDER NOCYCLE");
ps2.executeUpdate();
PreparedStatementps=con.prepareStatement("CREATE TABLE
QUIZCONTACT (NAME VARCHAR2(4000),EMAIL
VARCHAR2(4000),PHONE VARCHAR2(4000),MESSAGE
VARCHAR2(4000))");
ps.executeUpdate();
PreparedStatement ps4=con.prepareStatement("CREATE TABLE
QUIZINFO (SUBJECT VARCHAR2(4000),QUIZNAME
VARCHAR2(4000))");
ps4.executeUpdate();
}
}
public void contextDestroyed(ServletContextEvent arg0) {
System.out.println("project undeployed");
}
}
OUTPUT:
RESULT:
AIM:
PROGRAM:
importjava.awt.Canvas;
importjava.awt.Graphics;
import java.awt.Graphics2D;
importjava.awt.Shape;
import java.awt.geom.Ellipse2D;
importjava.awt.geom.GeneralPath;
import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.RoundRectangle2D;
importjavax.swing.JFrame;
public Draw2DObjects() {
add("Center", new MyCanvas());
shapes[0] = new Line2D.Double(0.0, 0.0, 100.0, 100.0);
shapes[1] = new Rectangle2D.Double(10.0, 100.0, 200.0, 200.0);
shapes[2] = new Ellipse2D.Double(20.0, 200.0, 100.0, 100.0);
GeneralPath path = new GeneralPath(new Line2D.Double(300.0, 100.0,
400.0, 150.0));
path.append(new Line2D.Double(25.0, 175.0, 300.0, 100.0), true);
shapes[3] = path;
shapes[4] = new RoundRectangle2D.Double(350.0, 250, 200.0, 100.0,
50.0, 25.0);
setSize(400, 400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
RESULT: