// Employee abstract superclass public abstract class Employee { private String firstName; private String lastName; private String SSN; private double salary; // three-argument constructor public
// Employee abstract superclass
public abstract class Employee { private String firstName; private String lastName; private String SSN; private double salary; // three-argument constructor public Employee( String first, String last, String ssn, double salary ) { firstName = first; lastName = last; SSN = ssn; } // end three-argument Employee constructor
// set first name public void setFirstName( String first ) { firstName = first; // should validate } // end method setFirstName
// return first name public String getFirstName() { return firstName; } // end method getFirstName
// set last name public void setLastName( String last ) { lastName = last; // should validate } // end method setLastName
// return last name public String getLastName() { return lastName; } // end method getLastName
// set social security number public void setSSN( String ssn ) { this.SSN = ssn; // should validate } // end method setSocialSecurityNumber
// return social security number public String getSSN() { return SSN; } // end method getSocialSecurityNumber
// return String representation of Employee object @Override public String toString() { return String.format( "%-12s%-12s%-12s", getFirstName(), getLastName(), getSSN() ); } // end method toString
// abstract method overridden by concrete subclasses public abstract double earnings(); // no implementation here } // end abstract class Employee
----------------------------------------------------------------
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
Step: 1
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started