Create a subfolder called polymorphism unit your unit 8 folder. Download the fol
ID: 3835693 • Letter: C
Question
Create a subfolder called polymorphism unit your unit 8 folder.
Download the following classes from Blackboard and save them in the Polymorphism folder you just created: Employee.java, Secretary.java, LegalSecretary.java, and Lawyer.java.
Review the source code for each of the files and compile them.
Add a toString method to the Employee class to print out the employee id and salary.
Write a class called Janitor to accompany the other employee classes. Janitors work twice as many hours per week as other employees (80 hours/week), they make $30,000, they get half as much vacation as other employees (only 5 days), and they have an additional method clean that prints “Workin’ for the man.” Make sure to interact with the superclass as appropriate.
Write a class called EmployeeTester.java that includes a main method. Create an array called lawFirm to hold 5 employee objects. Create one of each type of employee and store it in the array. You should have 5 objects created: an employee, janitor, a secretary, a legal secretary, and a lawyer. Write a for loop to print out all the employee objects and the number of vacation days for each employee. Separate the output for each employee with a blank line.
codes:
thank you
Explanation / Answer
Answer to q1. Add a toString method to class Employee (method added in class below)
}
}
Answer to q2. Janitor class
public class Janitor extends Employee{
Janitor(String id, double salary){
super(id, salary);
}
public void clean() {
System.out.println("Workin’ for the man.");
}
} // end of class Janitor
Answer to q3: EmployeeTester.java
public class EmployeeTester{
public static void main(String args[])
{
String idPrefix ="L00";
Employee[] lawFirm = new Employee[5];
lawFirm[0] = new Employee(idPrefix+"1",40000);
lawFirm[1] = new Janitor(idPrefix+"2",30000);
lawFirm[2] = new Secretary(idPrefix+"3",40000);
lawFirm[3] = new LegalSecretary(idPrefix+"4",50000);
lawFirm[4] = new Lawyer(idPrefix+"5",60000);
for(Employee e:lawFirm){
System.out.println(e.toString() + " No. of vacations= "+ e.getVacationDays());
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.