Java Lab Programs
Java Lab Programs
Java Lab Programs
NO:2
JAVA PROGRAM TO IMPLEMENT CURRENCY
CONVERTER, DISTANCE CONVERTER
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.
PROGRAM
currencyconversion.java
package currencyconversion;
import java.util.*;
double inr,usd;
double euro,yen;
usd=in.nextInt();
inr=usd*67;
inr=in.nextInt();
usd=inr/67;
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);
distance.java
package distanceconversion;
import java.util.*;
double km,m,miles;
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);
System.out.print(“Enter in km”);
km=sc.nextDouble();
miles=(km*0.621371);
timer.java
package timeconversion;
import java.util.*;
{
int hours,seconds,minutes;
int input;
input = sc.nextInt();
System.out.println(“Hours: ” + hours);
System.out.println(“Minutes: ” + minutes);
System.out.println(“Seconds: ” + seconds);
minutes=sc.nextInt();
hours=minutes/60;
minutes=minutes%60;
System.out.println(“Hours: ” + hours);
System.out.println(“Minutes: ” + minutes);
minutes=(hours*60);
System.out.println(“Minutes: ” + minutes);
hours=sc.nextInt();
seconds=(hours*3600);
System.out.println(“Minutes: ” + seconds);
}}
converter.java
import java.util.*;
import java.io.*;
import currencyconversion.*;
import distanceconversion.*;
import timeconversion.*;
class converter
int choice,ch;
System.out.println(“10.kilometer to miles”);
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;
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();
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 has been created for currency conversion, distance conversion and time
conversion and it was successfully executed.
EX.NO:3
JAVA PROGRAM TO GENERATE PAYSLIP USING
INHERITANCE
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.
5. Calculate gross salary and net salary.
6. Generate payslip for all categories of employees.
7. Create the objects for the inherited classes and invoke the necessary methods to display the
Payslip.
PROGRAM
import java.util.*;
class employee
{
int empid;
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 Name: “+name);
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(“************************************************”);
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);
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(“PAY SLIP FOR ASSISTANT PROFESSOR”);
System.out.println(“************************************************”);
System.out.println(“Basic Pay:Rs”+bp);
System.out.println(“DA:Rs”+da);
System.out.println(“HRA:Rs”+hra);
System.out.println(“PF:Rs”+pf);
System.out.println(“CLUB:Rs”+club);
System.out.println(“GROSS PAY:Rs”+gross);
System.out.println(“NET PAY:Rs”+net);
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(“************************************************”);
System.out.println(“Basic Pay:Rs”+bp);
System.out.println(“DA:Rs”+da);
System.out.println(“HRA:Rs”+hra);
System.out.println(“PF:Rs”+pf);
System.out.println(“CLUB:Rs”+club);
System.out.println(“GROSS PAY:Rs”+gross);
System.out.println(“NET PAY:Rs”+net);
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(“************************************************”);
System.out.println(“Basic Pay:Rs”+bp);
System.out.println(“DA:Rs”+da);
System.out.println(“HRA:Rs”+hra);
System.out.println(“PF:Rs”+pf);
System.out.println(“CLUB:Rs”+club);
System.out.println(“GROSS PAY:Rs”+gross);
System.out.println(“NET PAY:Rs”+net);
class salary
int choice,cont;
do
System.out.println(“PAYROLL”);
switch(choice)
case 1:
p.getdata();
p.getprogrammer();
p.displ0ay();
p.calculateprog();
break;
case 2:
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);
Result:
Thus the Java application has been created with with employee class and pay slips are generated for
the employees with their gross and net salary.