Design and implement the following classes: (A) An abstract class Employee that
ID: 3530991 • Letter: D
Question
Design and implement the following classes: (A) An abstract class Employee that represents a generic employee. Include methods to retrieve information about the employee. (B) A subclass of Employee called HourlyEmployee that describes an employee that gets paid by the hour. Include a public method called pay that returns the pay of the employee for that month, and other relevant methods. (C) A subclass of Employee called NonHourlyEmployee that describes an employee who gets paid a fixed salary every month. Include a public method called pay that returns the pay of the employee for that month. Include any other relevant methods.Explanation / Answer
public abstract class Employee {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public abstract String getEmployeeInfo();
}
public class HourlyEmployee extends Employee {
double payRate = 15;
@Override
public String getEmployeeInfo() {
return "Emp name " + getName() + " monthly pay: " + pay(240);
}
public double pay(int hours) {
return hours * payRate;
}
}
public class NonHourlyEmployee extends Employee {
@Override
public String getEmployeeInfo() {
return "Emp name " + getName() + " monthly pay: " + pay();
}
public double pay() {
return 30000;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.