1. Another Type of Employee The files Firm,java, Statfjava, StaffMemberjava, Vol
ID: 3801223 • Letter: 1
Question
1. Another Type of Employee The files Firm,java, Statfjava, StaffMemberjava, Volunteerjava, Employee, Executive java, and java, Hourly java are provided and can also be found from this word document. The program illustrates inheritance and polymorphism. In this exercise you will add one more employee type to the class hierarchy, called Commission The employee will be one that is an hourly employee but also earns a commission on sales. Hence the class which we'll name Commission, will be derived from the Hourly class Write a class named Commission with the following features: It extends the Hourly class It has two instance variables (in addition to those inherited): one is the total sales the employee has made (type double) and the second is the commission rate for the employee (the commission rate will be type double and will represent the percent (in decimal form commission the employee earns on sales (so.2 would mean the employee earns 20% commission on sales) The constructor takes 6 parameters: the first 5 are the same as for Hourly (name, address, phone number, social security number, hourly pay rate) and the 6th is the commission rate for the employee. The constructor should call the constructor of the parent class with the first 5 parameters then use the 6th to set the commission rate One additional method is needed: public void addSales (double totalSales) that adds the parameter to the instance variable representing total sales The pay method must call the pay method of the parent class to compute the pay for hours worked then add to that the pay from commission on sales. (See the pay method in the Executive class. The total sales should be set back to 0 (note: you don't need to set the hours Worked back to 0 why not?) The toString method needs to call the toString method of the parent class then add the total sales to that. To test your class, update Staff,java as follows Increase the size of the array to 8 Add two commissioned employees to the staffList make up your own names, addresses, phone numbers and social security numbers. Have one of the employees earn $6.25 per hour and 20% commission and the other one earn $9.75 per hour and 15% commission For the first additional employee you added, put the hours worked at 35 and the total sales $400; for the second, put the hours at 40 and the sales at $950 Compile and run the program. Make sure it is working properlyExplanation / Answer
Changes were made only in Staff.java and Commission.java
Staff.java
package commission;
public class Staff {
StaffMember staffList[];
public Staff() {
staffList = new StaffMember[8];
staffList[0] = new Executive("Sam", "123 Main Line", "555-0469", "123-45-6789", 2423.07);
staffList[1] = new Employee("Carla", "456 off Line", "555-0101", "987-65-4321", 1246.15);
staffList[2] = new Employee("Woody", "789 Off Rcoker", "555-0000", "010-20-3040", 1169.23);
staffList[3] = new Hourly("Diane", "678 fifth Ave.", "555-0690", "958-47-3625", 10.55);
staffList[4] = new Volunteer("Norm", "987 Sudds Blvd.", "555-8374");
staffList[5] = new Volunteer("Cliff", "321 Duds Lane", "555-7282");
((Executive)staffList[0]).awardBonus(500.00);
((Hourly)staffList[3]).addHours(40);
Commission comm_emp = new Commission("John", "435 Sixth Line", "555-7922", "742-76-1358", 6.25, 20);
comm_emp.addHours(35);
comm_emp.addSales(400);
Commission comm_emp_2 = new Commission("James", "123 Seventh Line", "555-9763", "874-15-9876", 9.75, 15);
comm_emp_2.addHours(40);
comm_emp_2.addSales(950);
staffList[6] = comm_emp;
staffList[7] = comm_emp_2;
}
public void payday()
{
double amount;
for(int count=0; count<staffList.length; count++)
{
System.out.println(staffList[count]);
amount = staffList[count].pay();
if(amount == 0)
System.out.println("Thanks!");
else System.out.println("Paid: " + amount);
System.out.println("---------------------------------------- ");
}
}
}
Commission.java
package commission;
public class Commission extends Hourly{
double totalSales;
double commissionRate;
public Commission(String eName, String eAddrr, String ePhone, String SocNumber, double rate, double commrate) {
super(eName, eAddrr, ePhone, SocNumber, rate);
commissionRate = commrate;
}
public void addSales(double totalSales)
{
this.totalSales = totalSales;
}
@Override
public double pay() {
double payment = super.pay() + ((totalSales * commissionRate)/100);
totalSales = 0;
return super.pay();
}
@Override
public String toString() {
String result = super.toString();
result += " Commision rate: " + commissionRate;
return result;
}
}
OUTPUT:
Name: Sam
Address: 123 Main Line
Phone: 555-0469
Social Security Number: 123-45-6789
Paid: 2923.07
----------------------------------------
Name: Carla
Address: 456 off Line
Phone: 555-0101
Social Security Number: 987-65-4321
Paid: 1246.15
----------------------------------------
Name: Woody
Address: 789 Off Rcoker
Phone: 555-0000
Social Security Number: 010-20-3040
Paid: 1169.23
----------------------------------------
Name: Diane
Address: 678 fifth Ave.
Phone: 555-0690
Social Security Number: 958-47-3625
Current Hours: 40
Paid: 422.0
----------------------------------------
Name: Norm
Address: 987 Sudds Blvd.
Phone: 555-8374
Thanks!
----------------------------------------
Name: Cliff
Address: 321 Duds Lane
Phone: 555-7282
Thanks!
----------------------------------------
Name: John
Address: 435 Sixth Line
Phone: 555-7922
Social Security Number: 742-76-1358
Current Hours: 35
Commision rate: 20.0
Thanks!
----------------------------------------
Name: James
Address: 123 Seventh Line
Phone: 555-9763
Social Security Number: 874-15-9876
Current Hours: 40
Commision rate: 15.0
Thanks!
----------------------------------------
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.