Develop a simple Java based payroll system that can calculate the weekly pay due for different categories of employees. The system should be implemented using the following design guidelines:
a: Implement an abstract base class called Employee that is used to hold basic information about an employee e.g. name, address, etc. This class should also define an abstract method called earnings() that returns the weekly pay for each type of employee. The class should include a suitable constructor and accessor methods to retrieve information about the employee. Include the private instance variable joinDate in class Employee to represent when they joined the company. Use the java.util.Date class for this variable.
b: Implement a class called Manager, derived from Employee. A manager is paid a fixed weekly salary. The class should include a suitable constructor and should also implement the earnings() method.
c: Implement a class called HourlyWorker, derived from Employee. An hourly worker is paid a fixed wage per hour, so in any given week they will be paid for the number of hours worked in the past week. The class should include a constructor and implement the earnings() method.
d: Write a short driver program that creates an array of Employee variables to store references to the various employee objects. In a loop, calculate the payroll for each Employee, and add a €100.00 bonus to the person’s payroll if they joined the company over 5 years ago.
SOURCE CODE:
*Please follow the comments to better understand the code.
**Please look at the Screenshot below and use this code to copy-paste.
***The code in the below screenshot is neatly indented for better understanding.
import java.util.Calendar;
import java.util.Date;
public abstract class Employee
{
// fields
private Date joinDate;
String name;
int id;
String address;
// earnings
abstract double earnings();
// constructor
public Employee(String name, int id, String address,Date joinDate) {
this.name = name;
this.id = id;
this.address = address;
this.joinDate=joinDate;
}
// accessor and mutator
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public Date getJoinDate() {
return joinDate;
}
public void setJoinDate(Date joinDate) {
this.joinDate = joinDate;
}
}
// manager class
class Manager extends Employee
{
// fields
private double weeklySalary;
// constructor
public Manager(String name, int id, String address, Date joinDate, double weeklySalary) {
super(name, id, address, joinDate);
this.weeklySalary = weeklySalary;
}
@Override
double earnings() {
return weeklySalary;
}
}
class HourlyWorker extends Employee
{
// fields
private int numHoursWorked;
private double payPerHour;
// constructor
public HourlyWorker(String name, int id, String address,Date joinDate, int numHoursWorked, double payPerHour) {
super(name, id, address, joinDate);
this.numHoursWorked=numHoursWorked;
this.payPerHour=payPerHour;
}
@Override
double earnings() {
return numHoursWorked*payPerHour;
}
}
class Driver
{
public static void main(String[] args) {
// create array of employees
Manager manager=new Manager("Manager",100,"XYZ",new Date(2013, Calendar.NOVEMBER,20),24000);
HourlyWorker worker1=new HourlyWorker("Worker1",101,"ABC",new Date(2018, Calendar.NOVEMBER,18),26, 100);
HourlyWorker worker2=new HourlyWorker("Worker2",102,"PQR",new Date(2012, Calendar.NOVEMBER,12),22, 100);
Employee[] employees= new Employee[]{manager, worker1, worker2};
// loop through and print the earnings
for(Employee employee:employees) {
double earnings = employee.earnings();
//check Date of joining and and add bonus
Date today=new Date();
double difference=( today.getTime() - employee.getJoinDate().getTime())/(24.0 * 60 * 60 * 1000*365);
if(difference>=5)
earnings += 100;
System.out.println(employee.name + " earns "+earnings+" per week.");
}
}
}
==========






Develop a simple Java based payroll system that can calculate the weekly pay due for different...