Professional Documents
Culture Documents
Lab #2
Tool Used:
Eclipse
Objective:
To perform java implementation code, with inheritance and polymorphism
Task 1:
A company pays its employees on a weekly basis. The employees are of four types: Salaried
employees are paid a fixed weekly salary regardless of the number of hours worked, hourly
employees are paid by the hour and receive overtime pay for all hours worked in excess of 40
hours, commission employees are paid a percentage of their sales and salaried-commission
employees receive a base salary plus a percentage of their sales. For the current pay period, the
company has decided to reward salaried-commission employees by adding 10% to their base
salaries. The company wants to implement a Java application that performs its payroll
calculations polymorphic-ally.
Derive all four classes and calculate their salary accordingly
Code:
import java.util.Scanner;
public class Emp1 {
}
}
class SCemployee extends Emp1{
private double sale2;
}
public void getData(String name2, String id2, double a, int b, int r) {
// TODO Auto-generated method stub
}
public void getData(String name2, String id2, double a, double sale) {
// TODO Auto-generated method stub
}
import java.util.Scanner;
/*import Emp.SCemployee;
import Emp.commissionEmployee;
import Emp.hourlyEmployee;
import Emp.salaryEmployee;*/
h.getData(name,id,a,b,r);
h.myCalculation();
break;
case 3:
System.out.println("Enter Employee name :");
name=s.nextLine();
name=s.nextLine();
System.out.println("Enter Employee ID :");
id=s.nextLine();
System.out.println("Enter Fixed base salary :");
a=s.nextDouble();
System.out.println("Enter Total sale :");
sale=s.nextDouble();
Emp1 c=e.new commissionEmployee();
c.getData(name,id,a,sale);
c.myCalculation();
break;
case 4:
System.out.println("Enter Employee name :");
name=s.nextLine();
name=s.nextLine();
System.out.println("Enter Employee ID :");
id=s.nextLine();
System.out.println("Enter Fixed base salary :");
a=s.nextDouble();
System.out.println("Enter Total sale :");
sale=s.nextDouble();
Emp1 sc=e.new SCemployee();
sc.getData(name,id,a,sale);
sc.myCalculation();
}
System.out.println("Do u want to continue Y/N");
ch=s.next().charAt(0);
}
while(ch=='Y'||ch=='y');
}
Abdullah Ayub(002) OOSE
Lab #2
}
Result:
Conclusion: Program run successfully.
Abdullah Ayub(002) OOSE
Lab #2