Question: public class Employee { String firstName; String lastName; String ssn; double salary; public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName
public class Employee {
String firstName; String lastName; String ssn; double salary; public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public String getSsn() { return ssn; } public void setSsn(String ssn) { this.ssn = ssn; } public double getSalary() { return salary; } public void setSalary(double salary) { this.salary = salary; } }
----------------------------------------------------------------
public class FullTimeEmployee extends Employee { private double weeklySalary; FullTimeEmployee(String firstname, String lastname, String SSN, double salary) { this.firstName = firstName; this.lastName = lastName; this.ssn = SSN; this.salary = weeklySalary; }
public double getWeeklySalary() { return weeklySalary; }
public void setWeeklySalary(double weeklySalary) { this.weeklySalary = weeklySalary; }
public double earnings() { return weeklySalary; } public String toString() { return this.getFirstName() + " " + this.getLastName() + " " + this.getWeeklySalary() + " " + this.getSsn(); } }
-----------------------------------------------------------------
public class PartTimeEmployee extends Employee { private double wage; private int hours; public double getWage() { return wage; }
public void setWage(double wage) { this.wage = wage; }
public int getHours() { return hours; }
public void setHours(int hours) { this.hours = hours; }
public PartTimeEmployee(String firstname, String lastname, String ssn, double wage, int hours) { this.firstName = firstname; this.lastName = lastname; this.ssn = ssn; this.wage = wage; this.hours = hours; }
public double earnings() { return weeklySalary; }
public String toString() { return this.getFirstName() + " " + this.getLastName() + " " + this.getSsn() + " " + (double)(this.getWage() * this.getHours()); } }
---------------------------------------
I cannot get PartTimeEmployee and FullTimeEmployee's constructors to play nice with Employee. I am supposed to use polymorphism with Employee's abstract class. I cannot change Employee's code. How can I make them play nice?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
