Modify the firm example from this chapter such that all employees can be given different vacation option depending in their classification , provide method called vacation that returns the number of vacation days a person has , give all employees standard number of vacation days (14) then override that method in the various employees classes as appropriate . modify the driver program to demonstrate this new functionality .
public class Firm {
public static void main (String[] args){
Staff personnel = new Staff();
personnel.payday();
}
}
public class Staff {
private StaffMember[] staffList;
public Staff(){
staffList = new StaffMember[4];
staffList[0] = new Executive (“George”, “123 Main Street”, “555‐5555”, “123‐45‐
6789″, 10000.00);
staffList[1] = new Employee (“Diane”, “456 Grand Ave.”, “666‐6666”, “012‐34‐
5678″, 4000.00);
staffList[2] = new Hourly (“Woody”, “789 Fifth Ave.”, “777‐7777”, “234‐56‐
7890″, 10.55);
staffList[3] = new Volunteer (“Jane”, “012 South Street”, “888‐8888”);
((Executive)staffList[0]).awardBonus(500.00);
((Hourly)staffList[2]).addHours(40);
}
public void payday(){
double amount;
for (int count = 0; count < staffList.length; count++){
// get type name of each object staff array
System.out.println(staffList[count].getClass().getName());
System.out.println(staffList[count]);
amount = staffList[count].pay();
if (amount == 0.0)
System.out.println(“Thanks!”);
else
System.out.println(“Paid: ” + amount);
System.out.println (“‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐”);
}
}
}
public abstract class StaffMember {
protected String name;
protected String address;
protected String phone;
public StaffMember (String iName, String iAddress, String iPhone){
name = iName;
address = iAddress;
phone = iPhone;
}
public String toString(){
String result = “Name: ” + name + “n”;
result += “Address: ” + address + “n”;
result += “Phone: ” + phone;
return result;
}
public abstract double pay();
}
public class Employee extends StaffMember{
protected String SSN;
protected double payRate;
public Employee(String iName, String iAddress, String iPhone, String iSSN,
double rate){
super (iName, iAddress, iPhone);
SSN = iSSN;
payRate = rate;
}
public String toString(){
String result = super.toString();
result += “nSSN: ” + SSN;
return result;
}
public double pay(){
return payRate;
}
}
public class Volunteer extends StaffMember{
public Volunteer (String iName, String iAddress, String iPhone){
super (iName, iAddress, iPhone);
}
public double pay(){
return 0.0;
}
}
public class Executive extends Employee{
private double bonus;
public Executive (String iName, String iAddress, String iPhone,
String SSN, double rate){
super (iName, iAddress, iPhone, SSN, rate);
bonus = 0;
}
public void awardBonus(double execBonus){
bonus = execBonus;
}
public double pay(){
double payment = super.pay() + bonus;
bonus = 0;
return payment;
}
}
public class Hourly extends Employee{
private int hoursWorked;
public Hourly (String iName, String iAddress, String iPhone, String iSSN,
double rate){
super (iName, iAddress, iPhone, iSSN, rate);
hoursWorked = 0;
}
public void addHours (int moreHours){
hoursWorked += moreHours;
}
public double pay(){
double payment = payRate * hoursWorked;
hoursWorked = 0;
return payment;
}
public String toString(){
String result = super.toString();result += “nCurrent hours: ” + hoursWorked;
return result;
}
}
i need it to solve before thursday
thanks