In: Computer Science
Design a class named Employee. The class should keep the following information in fields: • Employee name • Employee number in the format XXX–L, where each X is a digit within the range 0–9, and the L is a letter within the range A–M. • Hire date Write one or more constructors and the appropriate accessor and mutator methods for the class. Next, write a class named ProductionWorker that inherits from the Employee class. The ProductionWorker class should have fields to hold the following information: Shift (an integer) Hourly pay rate (a double) The workday is divided into two shifts: day and night. The shift field will be an integer value representing the shift that the employee works. The day shift is shift 1, and the night shift is shift 2. Write one or more constructors and the appropriate accessor and mutator methods for the class. Demonstrate the classes by writing a program that uses a ProductionWorker object. In a particular factory, a shift supervisor is a salaried employee who supervises a shift. In addition to a salary, the shift supervisor earns a yearly bonus when his or her shift meets production goals. Design a ShiftSupervisor class that inherits from the Employee class. The ShiftSupervisor class should have a field that holds the annual salary, and a field that holds the annual production bonus that a shift supervisor has earned. Write one or more constructors and the appropriate accessor and mutator methods for the class. In a particular factory, a team leader is an hourly paid production worker who leads a small team. In addition to hourly pay, team leaders earn a fixed monthly bonus. Team leaders are required to attend a minimum number of hours of training per year. Design a TeamLeader class that inherits from the ProductionWorker class. The TeamLeader class should have fields for the monthly bonus amount, the required number of training hours, and the number of training hours that the team leader has attended. Write one or more constructors and the appropriate accessor and mutator methods for the class. Demonstrate the classes by writing a program that uses a TeamLeader object and a ShiftSupervisor object, as well as an Employee object. Be sure that all methods defined are called.
class Employee
{
//variables
private String name;
private String empNum;
String hiredate;
//constructor
public Employee(String name,String empNum,String hiredate)
{
this.name = name;
this.empNum = empNum;
this.hiredate = hiredate;
}
//set and get methods
public void setName(String name)
{
this.name = name;
}
public void setEmpNum(String empNum)
{
this.empNum = empNum;
}
public void setHiredate(String hiredate)
{
this.hiredate = hiredate;
}
public String getName()
{
return name;
}
public String getEmpNum()
{
return empNum;
}
public String getHiredate()
{
return hiredate;
}
public void display()
{
System.out.print("\nName: "+getName());
System.out.print("\nEmployee number: "+getEmpNum());
System.out.print("\nHire date: "+getHiredate());
}
}
class ProductionWorker extends Employee
{
private int shift;
private double hourlyPayRate;
//passing parameters to base class Employee from derived class
ProductionWorker
public ProductionWorker(String name,String empNum,String
hiredate,int shift,double hourlyPayRate)
{
super(name,empNum,hiredate);
this.shift = shift;
this.hourlyPayRate = hourlyPayRate;
}
//get and set functions
public void setShift(int shift)
{
this.shift = shift;
}
public void setHouryPayRate(double hourlyPayRate)
{
this.hourlyPayRate = hourlyPayRate;
}
public double getShift()
{
return shift;
}
public double getHourlyPayRate()
{
return hourlyPayRate;
}
public void displayDetails()
{
super.display(); //call to Employee class function
System.out.print("\nShift: $"+getShift());
System.out.print("\nHourly Pay Rate : "+getHourlyPayRate());
}
}
class TeamLeader extends ProductionWorker
{
private double monthlyBonus;
private int reqTrainingHours;
private int attendedHours;
public TeamLeader(String name,String empNum,String hiredate,int
shift,double hourlyPayRate,double monthlyBonus,int
reqTrainingHours,int attendedHours)
{
super(name,empNum,hiredate,shift,hourlyPayRate);
this.monthlyBonus = monthlyBonus;
this.reqTrainingHours = reqTrainingHours;
this.attendedHours = attendedHours;
}
//get and set functions
public void setMonthlyBonus(double monthlyBonus)
{
this.monthlyBonus = monthlyBonus;
}
public void setReqTrainingHours(int reqTrainingHours)
{
this.reqTrainingHours = reqTrainingHours;
}
void setAttendedHours(int attendedHours)
{
this.attendedHours = attendedHours;
}
public double getMonthlyBonus()
{
return monthlyBonus;
}
public int getReqTrainingHours()
{
return reqTrainingHours;
}
public int getAttendedHours()
{
return attendedHours;
}
public void displayDetails()
{
System.out.print("\nTeam leader : ");
super.display(); //call to Employee class function
System.out.print("\nMonthly Bonus : $"+getMonthlyBonus());
System.out.print("\nRequired Training Hours :
"+getReqTrainingHours());
System.out.print("\nAttended Training Hours :
"+getAttendedHours());
}
}
class ShiftSupervisor extends Employee
{
private double annualSalary;
double annualProductionBonus;
//passing parameters to base class Employee from derived
classShiftSupervisor
public ShiftSupervisor(String name,String empNum,String
hiredate,double annualSalary,double annualProductionBonus)
{
super(name,empNum,hiredate);
this.annualSalary = annualSalary;
this.annualProductionBonus = annualProductionBonus;
}
//get and set functions
void setAnnualSalary(double annualSalary)
{
this.annualSalary = annualSalary;
}
public void setAnnualProductionBonus(double
annualProductionBonus)
{
this.annualProductionBonus = annualProductionBonus;
}
public double getAnnualSalary()
{
return annualSalary;
}
public double getAnnualProductionBonus()
{
return annualProductionBonus;
}
public void displayDetails()
{
super.display(); //call to Employee class function
System.out.print("\nAnnual Salary: $"+getAnnualSalary());
System.out.print("\nAnnual Production Bonus:
$"+getAnnualProductionBonus());
}
}
class Test
{
public static void main (String[] args)
{
TeamLeader tl= new
TeamLeader("Andrew
Johnson","676-A","10/21/2010",1,7.8,500.50,40,25);
tl.displayDetails();
ShiftSupervisor ss = new ShiftSupervisor("John
Doe","859-M","7/24/2014",75000,15000);
ss.displayDetails();
}
}
Output:
Team leader : Name: Andrew Johnson Employee number: 676-A Hire date: 10/21/2010 Monthly Bonus : $500.5 Required Training Hours : 40 Attended Training Hours : 25 Name: John Doe Employee number: 859-M Hire date: 7/24/2014 Annual Salary: $75000.0 Annual Production Bonus: $15000.0
Do ask if any doubt. Please upvote.