Divina Oops Record
Divina Oops Record
(AUTONOMOUS), TIRUNELVELI
LABORATORY RECORD
ENGINEERING
1
FRANCIS XAVIER ENGINEERING COLLEGE
(AUTONOMOUS) , TIRUNELVELI-627003
BONAFIDE CERTIFICATE
2
INDEX
PAGE
EX.NO DATE NAME OF THE EXPERIMENT MARKS SIGN
NO
1(a) 12/08/2021 4
Electricity Bill Generation
1(b) 12/08/2021 11
Students Performance Analysis
2(a) 19/08/2021 15
Currency, Distance and Time Converter
2(b) 26/08/2021 28
Arithmetic Calculator
3 26/08/2021 32
Generating Pay Roll Slip For Employees
4 01/09/2021 42
Stack ADT Using Java Interface
5 06/09/2021 50
Perform String Operations Using ArrayList
6 08/09/2021 56
Abstract Class
7 13/09/2021 63
User Defined Exception Handling
8 13/09/2021 67
File Program
9 15/09/2021 73
Multi-Thread Program
10 15/09/2021 81
Generic Function
11 30/09/2021 85
Calculator
12 10/11/2021
Mini Project Using Java
3
Ex. No: 1 ELECTRICITY BILL GENERATION
Date:12/08/2021
OBJECTIVE:
PROCEDURE:
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
be paid as follows:
First 100 units –Rs
2 per unit
import java.io.*;
import java.util.*;
class Eb
double monthread;
String customernumber=s.nextLine();
String customername=s.nextLine();
double prevmonthreading=s.nextDouble();
double curmonthreading=s.nextDouble();
monthread=curmonthreading-prevmonthreading;
2 for commercial)");
int choice=s.nextInt();
switch(choice)
case 1:
5
{
if(monthread<=100)
(2.50*monthread));
(4*monthread));
else if(monthread>=501)
(6*monthread));
6
else
break;
case 2:
if(monthread<=100)
(4.50*monthread));
7
else if(monthread>=501)
else
break;
Eb E=new Eb();
E.cust();
8
OUTPUT:
9
CONCLUSION:
10
Ex. No: 1(b) STUDENTS PERFORMANCE ANALYSIS
Date:12/08/2021
OBJECTIVE:
PROCEDURE:
STEP-3: Based on the percentage per, the class will be displayed as follows:
>75 percentage –
Distinction
60-75 percentage
–First class
<60 percentage
–Second class
STEP-4: Display all the details.
11
PROGRAM:
import java.io.*;
import java.util.*;
class student1
int rno,m1,m2,m3,total;
String name;
float per;
System.out.println("Class: Distinction");
}
else if(per>=60 && per<=74)
12
{
System.out.println("Class:First Class");
else if(per<60)
System.out.println("Class:Second Class");
}
else
{
System.out.println();
}
s.stud();
13
OUTPUT:
RESULT:
Thus the Java program to analyze the performance of the students has
been created and executed successfully.
14
Ex. No: 2a CURRENCY, DISTANCE AND TIME CONVERTER
Date:19/08/2021
OBJECTIVE:
PROCEDURE:
STEP-9: Create a new java program and import the package Myownpackage.
STEP-10: Use switch cases to call the functions which we have used in the
previous program
15
PROGRAM-1:
package Myownpackage;
import java.io.*;
import java.util.*;
public class A
int choice;
System.out.println("1.Dollar to INR");
System.out.println("2.INR to Dollar");
System.out.println("3.YEN to INR");
System.out.println("5.Euro to INR");
System.out.println("6.INR to Euro");
choice=s.nextInt();
switch(choice)
case 1:
double dollar;
16
System.out.println("Enter the Dollar Amount to be converted to INR:");
dollar=s.nextDouble();
case 2:
double Inr;
case 3:
double Yen;
+(Yen*40.0)); break;
case 4:
double Inr;
17
System.out.println("Enter the INR Amount to be converted to
YEN:"); Inr=s.nextDouble();
case 5:
double Euro;
case 6:
double Inr;
int choice;
System.out.println("1.Metres to Kilometer");
System.out.println("2.Kilometer to Metres");
System.out.println("3.Miles to Kilometer");
choice=s.nextInt();
switch(choice)
{case 1:
double metre;
Kilometres:");
metre=s.nextDouble();
(metre*0.001));
break;
case 2:
double km;
(km/0.001)); break;
case 3:
double miles;
Kilometres:"); miles=s.nextDouble();
break;
case 4:
double km;
Miles:"); km=s.nextDouble();
(km/1.609344)); break;
int choice;
20
System.out.println("The Choices are ");
System.out.println("1.Hours to Minutes");
System.out.println("2.Minutes to Hours");
System.out.println("3.Seconds to Hours");
choice=s.nextInt();
switch(choice)
case 1:
int hrs;
case 2:
int mnts;
Hours:"); mnts=s.nextInt();
(mnts/60)); break;
21
}
case 3:
int seconds;
case 4:
int hrs;
22
PROGRAM-2:
import Myownpackage.A;
import java.io.*;
import java.util.*;
class Next
int ch;
A ob=new A();
do
System.out.println("2.Distance Converter");
System.out.println("3.Time Converter");
ch=s.nextInt();
switch(ch)
case 1:
ob.MConverter();
break;
23
case 2:
ob.DConverter();
break;
case 3:
ob.TConverter();
break;
}while(ch<=3);
24
24
OUTPUT-1:
25
25
26
26
CONCLUSION:
Thus a Java application has been created to perform Currency,
Distance and Time converters using packages and implemented successfully.
27
Ex. No: 2(b) ARITHMETIC CALCULATOR
Date:26/08/2021
OBJECTIVE:
PROCEDURE:
STEP-3: Create a user defined class Calculator with a member function named calc()
STEP-4: Use switch cases to perform arithmetic operations such as addition, subtraction,
multiplication and division .
STEP-5: Create a new java program compute.java and import the package calculator.
28
PACKAGE:
package calculator;
import java.util.Scanner;
num1 = scanner.nextDouble();
System.out.print("Enter second number:");
num2 = scanner.nextDouble();
scanner.close();
double output;
switch(operator)
{
case '+':
output = num1 + num2;
break;
case '-':
output = num1 - num2;
break;
case '*':
output = num1 * num2;
break;
case '/':
output = num1 / num2;
break;
default:
System.out.printf("You have entered wrong operator");
return;
}
30
OUTPUT:
RESULT:
31
Ex.No:3 GENERATING PAY ROLL SLIP FOR EMPLOYEES
Date:26/08/2021
OBJECTIVE:
PROCEDURE:
STEP-1: Decalre Class Employee and Define the Method void display()
STEP-2: Declare class Programmer and extends Employee. Define
Programmer () constructor and calculate bp, hra, da, pf and salary.
STEP-3: Declare class AssistProf and extends Employee. Define AssistProf
() constructor and calculate bp, hra, da, pf and salary.
STEP-4: Declare class AssoProf and extends Employee. Define AssoProf ()
constructor and calculate bp, hra, da, pf and salary.
STEP-5: Declare class Professor and extends Employee. Define Professor ()
constructor and calculate bp, hra, da, pf and salary.
STEP-6: Declare main class as Employee and create instances of those
classes and call display() method and print the details.
32
PROGRAM:
import java.io.*;
import java.util.Scanner;
class Employee
{
int Emp_id,Mobile_no;
String Emp_name,address,Mail_id;
public Employee()
{
Emp_name=get.nextLine();
Mail_id=get.nextLine();
address=get.nextLine();
Emp_id=get.nextInt();
Mobile_no=get.nextInt();
void display()
{
System.out.println("Employee id:"+Emp_id);
System.out.println("Employee name:"+Emp_name);
33
System.out.println("Employee mail:"+Mail_id);
System.out.println("Employee address:"+address);
float bp,salary,hra,da,swf,pf;
public Programmer()
{
bp=get.nextFloat();
hra=bp*10/100;
da=bp*97/100;
pf=bp*12/100;
swf=bp*1/10000;
salary=bp+hra+da-pf-swf;
void display()
System.out.println("Programmer Details:");
super.display();
System.out.println("Basic Pay:"+bp);
System.out.println("HRA:"+hra);
System.out.println("DA:"+da);
34
System.out.println("Staff welare amount:"+swf);
System.out.println("P F:"+pf);
System.out.println("Salary:"+salary);
float bp,salary,hra,da,swf,pf;
public AssistProf()
{
bp=get.nextFloat();
hra=bp*10/100;
da=bp*97/100;
pf=bp*12/100;
swf=bp *1/10000;
salary=bp+hra+da-pf-swf;
void display()
super.display();
System.out.println("Basic Pay:"+bp);
35
System.out.println("HRA:"+hra);
System.out.println("DA:"+da);
System.out.println("P F:"+pf);
System.out.println("Salary:"+salary);
float bp,salary,hra,da,swf,pf;
public AssoProf() {
bp=get.nextFloat();
hra=bp*10/100;
da=bp*97/100;
pf=bp*12/100;
swf=bp *1/10000;
salary=bp+hra+da-pf-swf;
void display()
System.out.println("Associate Professor
Details:");
super.display();
36
System.out.println("Basic Pay:"+bp);
System.out.println("HRA:"+hra);
System.out.println("DA:"+da);
System.out.println("P F:"+pf);
System.out.println("Salary:"+salary);
}
}
float bp,salary,hra,da,swf,pf;
public Professor()
{
System.out.println("Enter Bas Pay:");
bp=get.nextFloat();
hra=bp*10/100;
da=bp*97/100;
pf=bp*12/100;
swf=bp *1/10000;
salary=bp+hra+da-pf-swf;
}
void display()
37
System.out.println("Professor Details:");
super.display();
System.out.println("Basic Pay:"+bp);
System.out.println("HRA:"+hra);
System.out.println("DA:"+da);
System.out.println("P F:"+pf);
System.out.println("Salary:"+salary);
}
}
public class Employees
{
public static void main(String[] args)
{
System.out.println("Enter Employee Details:");
Employee e=new Employee();
e.display();
obj1.display();
obj2.display();
obj3.display();
obj4.display();
} 38
OUTPUT-1:
39
40
CONCLUSION:
Thus the Java program has been created to generate pay slips and
it has been implemented successfully.
41
Ex.No : 4 STACK ADT USING JAVA INTERFACE
Date:01/09/2021
OBJECTIVE:
To design a java interface for ADT stack. Implement this interface using
array. Provide necessary exception handling in both the implementation.
PROCEDURE:
42
PROGRAM:
import java.io.*;
interface Mystack
int top=-1;
try
if(top==(n-1))
return;
43
else
catch(IOException e)
System.out.println("e");
if(top<0)
System.out.println("Stack underflow");
return;
else
int popper=stack[top];
top--;
System.out.println("Popped element:" +popper);
44
}
if(top<0)
System.out.println("Stack is empty");
return;
else
System.out.println("Elements are:"+str);
class Stack_ADT
45
(System.in));
do
ch=Integer.parseInt(br.readLine()); switch(ch)
case 1:
stk.push();
break;
case 2:
stk.pop();
break;
case 3:
stk.display();
break;
case 4:
System.exit(0);
46
while(ch<5);
47
OUTPUT:
48
CONCLUSION:
Thus the Java program has been created to design a java
interface for STACK ADT and it has been implemented successfully.
49
Ex.No:05 PERFORM STRING OPERATIONS USING ARRAYLIST
Date:06/09/2021
OBJECTIVE:
To write a program to perform append , insert, search and list all
strings with given letter operations using ArrayList.
PROCEDURE:
STEP-1: Append the given string to the arraylist using add() method.
STEP-2: Insert the element at the particular index. Firstly get the index and
string and then use add(index,strobj) method to add the element at particular
index.
STEP-3: Get the element and find whether the element is present or not
using listobj.contains() method. It return either true or false.
STEP-4: Get a letter from input and use obj.startsWith(strobj) method find the
element.
50
PROGRAM:
import java.io.*;
import java.util.*;
int choice;
int k=1;
while(k==1)
{
System.out.println("1.append an element-at end 2.Insert-at particular Index
\n 3.Search \n 4.List all string starts with given Letter");
System.out.println("5.Display \n 6.Exit");
choice=get.nextInt();
switch(choice)
case 1 : {
System.out.println("Enter an element");
x=get.next();
al.add(x);
break;
51
case 2 :{
System.out.println("Enter index:");
int y=get.nextInt();
System.out.println("Enter an element");
x=get.nextLine();
al.add(y,x);
break;
case 3:{
String el=get.next();
if(al.contains(el))
else{
break;
case 4:{
52
String letter=get.next();
for(String i:al)
{
if(i.startsWith(letter))
{
System.out.println(i);
}
}
break;
}
case 5:{
if(al.isEmpty())
System.out.println("Empty List");
for(String i:al)
System.out.println(i);
break;
case 6 :{
k=2;
break;
default:{
System.out.println("try 1-6");
}
}
}
} 53
OUTPUT:
54
CONCLUSION:
Thus the Java program has been created to perform string
operations using ArrayList and it has been implemented successfully.
55
Ex.No: 06 ABSTRACT CLASS
Date:08/09/2021
OBJECTIVE:
PROCEDURE:
56
PROGRAM:
import java.io.*;
import java.util.*;
int x,y;
void print_area()
int area;
x=s.nextInt();
y=s.nextInt();
area=x*y;
57
void print_area()
double area;
x=s.nextInt();
y=s.nextInt();
area=(double)((x*y)/2);
void print_area()
double area;
x=s.nextInt();
area=3.14*x*x;
class Main
58
public static void main(String args[])
int choice;
do
choice=sc.nextInt();
switch(choice)
case 1:
r.print_area();
break;
case 2:
t.print_area();
break;
59
}
case 3:
c.print_area();
break;
}while(choice<4);
60
OUTPUT:
61
CONCLUSION:
62
Ex.No:07 USER DEFINED EXCEPTION HANDLING
Date:13/09/2021
OBJECTIVE:
To write a Java program to implement user defined exception handling
PROCEDURE:
STEP-6: In the main() function, use try block to perform necessary operations
63
PROGRAM:
import java.io.*;
String str1;
MyException(String str2) {
str1=str2;
class Example1{
try{
catch(MyException exp){
System.out.println("Catch Block")
; System.out.println(exp) ;
64
OUTPUT:
65
CONCLUSION:
Thus the Java program has been created to handle the
user defined exception and it has been implemented successfully.
66
Ex.No:08 FILE PROGRAM
Date:13/09/2021
OBJECTIVE:
To write a java program that reads a file name from the user and displays
information about whether the file is readable, or writable, the type of file and
the length of the file in bytes.
PROCEDURE:
67
PROGRAM:
import java.io.*;
InputStreamReader(System.in));
if(f.exists())
{
System.out.println("The file length is "+f.length()+"in bytes");
if(fName.endsWith(".jpg")||fName.endsWith(".gif")||fName
.endsWith(".png"))
else if(fName.endsWith(".exe")){
else if(fName.endsWith(".txt"))
{ 68
System.out.println("The given file is a text file");
69
else if(fName.endsWith(".java"))
else
70
OUTPUT:
71
CONCLUSION:
Thus the program the reads the file name and displays the
information about the file is executed and verified successfully.
72
Ex.No:09 MULTI-THREAD PROGRAM
Date:15/09/2021
OBJECTIVE:
PROCEDURE:
STEP-7: After all the integers are generated the execution of the threads stops.
73
PROGRAM:
double num;
try
squareThread.start();
cubeThread.start();
for(int i=0;i<5;i++)
System.out.println("t1-"+i);
if(i%2==0)
sqt.setNum(new Double(i));
else
cbt.setNum(new Double(i));
74
}
Thread.sleep(1000);
catch(InterruptedException e)
e.printStackTrace();
Double num;
try
int i=0;
do
i++;
if(num!=null&&num%2==0)
"+(num*num));
75
num=null;
Thread.sleep(1000);
}while(i<=5);
catch(Exception e)
e.printStackTrace();
return num;
this.num=num;
Double num;
76
try
int i=0;
do
i++;
if(num!=null&&num%2!=0)
{
System.out.println("t3-->Cube of
"+num+"="+(num*num*num));
num=null;
Thread.sleep(1000);
}while(i<=5);
catch(Exception e)
e.printStackTrace();
return num;
77
{
this.num=num;
Random()); randomThread.start();
78
OUTPUT:
79
CONCLUSION:
Thus, the required program that generates integers and prints
its square or cube based on that integer, is executed and verified successfully.
80
Ex. No: 10 GENERIC FUNCTION
Date:15/09/2021
OBJECTIVE:
To write a java program to find the maximum value from the given
type of elements using a generic function.
PROCEDURE:
STEP-3: Sets the first value in the array as the current maximum
STEP-4: Find the maximum value by comparing each elements of the array
81
PROGRAM:
import java.io.*;
for(int i=0;i<list.length;i++)
list[i]=i;
}
System.out.println("Max="+max(list));
}
return max;
}
max=list[0];
for(inti=1;i<list.length;i++)
{
E element=list[i];
if(element.compareTo(max)>0)
{
max=element;
}
}
return max;
82
OUTPUT:
83
CONCLUSION:
Thus the implementation of generic function is achieved for finding the
maximum value from the given type of elements.
84
Ex. No.: 11 CALCULATOR
Date:30/09/2021
OBJECTIVE:
To design a calculator using event-driven programming paradigm
of Java for Decimal manipulations and Scientific manipulations.
PROCEDURE:
STEP-2: Using the swing components design the buttons of the calculator
STEP-3: Use key events and key listener to listen the events of the calculator.
85
PROGRAM:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
{
private final Font BIGGER_FONT=new Font("monspaced",Font.PLAIN,20);
private JTextFieldtextfield;
textfield=new JTextField("",12);
textfield.setHorizontalAlignment(JTextField.RIGHT);
textfield.setFont(BIGGER_FONT);
ActionListenernumberListener=new
JPanelbuttonPanel=new JPanel();
buttonPanel.setLayout(new GridLayout(4,4,4,4));
for(inti=0;i<buttonOrder.length();i++) {
String Key=buttonOrder.substring(i,i+1);
86
if(Key.equals(""))
buttonPanel.add(new JLabel(""));
else
button.addActionListener(numberListener);
button.setFont(BIGGER_FONT);
buttonPanel.add(button); }
ActionListeneroperatorListener=new
panel.setLayout(new GridLayout(4,4,4,4));
String[]opOrder={"+","-","*","/","=","C","sin","cos","log"};
for(inti=0;i<opOrder.length;i++)
button.addActionListener(operatorListener);
button.setFont(BIGGER_FONT);
panel.add(button);
87
pan.setLayout(new BorderLayout(4,4));
pan.add(textfield,BorderLayout.NORTH);
pan.add(buttonPanel,BorderLayout.CENTER);
pan.add(panel,BorderLayout.EAST);
this.setContentPane(pan); this.pack();
this.setTitle("Calculator");
this.setResizable(false);
number=true;
textfield.setText("");
equalOp="=";
op.setTotal("");
String displayText=textfield.getText();
if(e.getActionCommand().equals("sin"))
textfield.setText(""+Math.sin(Double.valueOf(displayText).doubleValue()));
88
}
else
if(e.getActionCommand().equals("cos"))
textfield.setText(""+Math.cos(Double.valueOf(displayText).doubleValue()));
else
if(e.getActionCommand().equals("log"))
textfield.setText(""+Math.log(Double.valueOf(displayText).doubleValue()));
else if(e.getActionCommand().equals("c"))
textfield.setText("");
else
if(number)
action();
textfield.setText("");
else
89
number=true;
if(equalOp.equals("="))
op.setTotal(displayText);
}else
if(equalOp.equals("+"))
op.add(displayText);
else if(equalOp.equals("-"))
op.subtract(displayText);
else if(equalOp.equals("*"))
op.multiply(displayText);
else if(equalOp.equals("/"))
op.divide(displayText);
textfield.setText(""+op.getTotalString());
equalOp=e.getActionCommand();
90
}
String digit=event.getActionCommand();
if(number)
textfield.setText(digit);
number=false;
else
textfield.setText(textfield.getText()+digit);
public CalculatorOp()
91
total=0;
return""+total;
total=convertToNumber(n);
total+=convertToNumber(n);
total-=convertToNumber(n);
total*=convertToNumber(n);
92
total/=convertToNumber(n);
private intconvertToNumber(String n)
return Integer.parseInt(n);
class MAIN
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
93
OUTPUT:
94
CONCLUSION:
Thus the implementation of generic function is achieved for
finding the maximum value from the given type of elements.
95
Ex .No:12 MINI PROJECT USING JAVA
Date:
OBJECTIVE:
PROCEDURE:
STEP-1: The doMenu() function is used to display the menu of the reservation.
import java.io.*;
//**************************************
//
//
// Inputs:None
//
// Returns:None
//
//
//Side Effects:NO ``
//**************************************
*/
int pcount=0;
int pnum=1;
int max1=75;
int max2=125;
int max3=175;
int cho;
do
doHeading();
System.out.println("1.Book ticket");
System.out.println("2.Cancel ticket");
System.out.println("3.Search passenger");
System.out.println("4.Reservation chart");
System.out.println("5.Displayunbooked tickets");
System.out.println("6.Exit");
System.out.println("Please enter your choice");
cho=Integer.parseInt(br.readLine());
switch(cho)
case 1:doBook();
break;
case 2:doCancel();
break;
case 3:doSearch();
break;
case 4:doDispList();
break;
case 5:doDispUnbooked();
break;
case 6:doExit();
break;
}while(cho!=6);
System.out.println("###########################################
##############");
System.out.println("*********Railway Reservation ForNellai
Express***********");
System.out.println("###########################################
##############");
t=Integer.parseInt(br.readLine());
intticketAvailable=0;
ticketAvailable=1;
ticketAvailable=1;
{
ticketAvailable=1;
if(ticketAvailable==1)
for(inti=0;i<t;i++)
pno[pcount]=pnum;
name[pcount]=br.readLine();
System.out.println("Please enter your age");
age[pcount]=Integer.parseInt(br.readLine());
cl[pcount]=c;
System.out.println("Ticket successfully
booked"); }//for
if(c==1)
max1-=t;
if(c==2)
max2-=t;
if(c==3)
max3-=t;
{
intt_pno[]=new int[275];
intt_age[]=new int[275];
intt_cl[]=new int[275];
intt_pcount=0;
intpassengerFound=0;
System.out.println("Please enter your passenger no.");
int p=Integer.parseInt(br.readLine());
for(inti=0;i<pcount;i++)
if(pno[i]!=p)
{//transfer
t_pno[t_pcount]=pno[i];
t_name[t_pcount]=name[i];
t_phno[t_pcount]=phno[i];
t_age[t_pcount]=age[i];
t_cl[t_pcount]=cl[i];
t_pcount++;
else
passengerFound=1;
if(cl[i]==1)
max1++;
System.out.println("Please collect refund of Rs."+1800);
if(cl[i]==2)
max2++;
System.out.println("Please collect refund of Rs."+1500);
if(cl[i]==3)
{
max3++;
System.out.println("Please collect refund of
Rs."+1000); }//else
}//if
if(passengerFound==1)
pno=t_pno;
name=t_name;
age=t_age;
cl=t_cl;
phno=t_phno;
pcount=t_pcount;
}//method
if(cl[i]==1)
System.out.println(pno[i]+"\t"+name[i]+"\t\t"+age[i]+"\t"+phno[i]);
if(cl[i]==2)
System.out.println(pno[i]+"\t"+name[i]+"\t\t"+age[i]+"\t"+phno[i]);
if(cl[i]==3)
System.out.println(pno[i]+"\t"+name[i]+"\t\t"+age[i]+"\t"+phno[i]);
{
intpassengerFound=0;
if(pno[i]==p)
System.out.println("Detail found");
passengerFound=1;
System.out.println("passenger no.="+pno[i]);
System.out.println("name="+name[i]);
System.out.println("class="+cl[i]);
System.out.println("phno="+phno[i]);
System.out.println("age="+age[i]);
}//for
if(passengerFound==0)
}//method
System.out.println("AC class"+max1);
System.out.println("First class"+max2);
System.out.println("Sleeper class"+max3);
System.exit(0);
}
OUTPUT:
CONCLUSION:
Thus the mini project (Railway reservation) using
java programming language is executed and verified successfully.