Question
A company pays its employees on a weekly basis. The employees are of five types: Salaried employees are paid a fixed weekly salary regardless of
A company pays its employees on a weekly basis. The employees are of five types:
- Salaried employees are paid a fixed weekly salary regardless of the number of hours worked,
- Hourly employees are paid by the hour and receive overtime pay (i.e., 1.5 times their hourly salary rate) for all hours worked in excess of 40 hours,
- Piece workers are paid by the number of merchandise produced in a week,
- Commission employees are paid a percentage (10% for example) of their sales.
- Salaried-commission employees are paid a base salary plus a percentage (5% for example) of total sales to their base salaries.
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
import java.util.ArrayList; public class PayrollSystemTester { public static void main( String args[] ) { // create an ArrayList to hold different types of employee objects. ArrayList employees = new ArrayList<>(); // initialize the arraylist emploees with Employees employees.add(new SalariedEmployee( "James", "Lebron", "121-11-1111", 1200.00)); employees.add(new HourlyEmployee("Maria", "Garcia", "232-22-2222", 26.75, 50)); employees.add( new CommissionEmployee("David", "Kim", "343-33-3333", 20000, .07)); employees.add( new BasePlusCommissionEmployee( "John", "Miller", "454-44-4444", 9000, .05, 900)); employees.add( new PieceWorker("Robert", "Green", "565-55-5555", 7.25, 700)); employees.add(new SalariedEmployee( "Jeff", "Turner", "111-11-1111", 800.00 )); employees.add(new HourlyEmployee("Samuel", "Bryant", "222-22-2222", 16.75, 40)); employees.add( new CommissionEmployee("Avery", "Butler", "333-33-3333", 10000, .06)); employees.add( new BasePlusCommissionEmployee( "Lucas", "Wood", "444-44-4444", 5000, .04, 300)); employees.add( new PieceWorker("Robert", "Williams", "555-55-5555", 2.25, 400));
System.out.println( "Employees processed polymorphically: " ); // generically process each element in array employees double salariedEmployeeTotal = 0; double hourlyEmployeeTotal = 0; double commissionEmployeeTotal = 0; double commissionPlusEmployeeTotal = 0; double pieceWorkerEmployeeTotal = 0; for ( Employee currentEmployee : employees ) { System.out.println( currentEmployee ); // invokes toString System.out.printf( "earned $%,.2f ", currentEmployee.earnings() ); if (currentEmployee instanceof SalariedEmployee) salariedEmployeeTotal += currentEmployee.earnings(); else if (currentEmployee instanceof HourlyEmployee) hourlyEmployeeTotal += currentEmployee.earnings(); else if (currentEmployee instanceof BasePlusCommissionEmployee) commissionPlusEmployeeTotal += currentEmployee.earnings(); else if (currentEmployee instanceof CommissionEmployee) commissionEmployeeTotal += currentEmployee.earnings(); else pieceWorkerEmployeeTotal += currentEmployee.earnings(); } // end for System.out.printf (" %-40s%10.2f","Salaried Employee Total:", salariedEmployeeTotal); System.out.printf (" %-40s%10.2f","Hourly Employee Total:", hourlyEmployeeTotal); System.out.printf (" %-40s%10.2f","Commission Employee Total:", commissionEmployeeTotal); System.out.printf (" %-40s%10.2f","Base Plus Commission Employee Total:", commissionPlusEmployeeTotal); System.out.printf (" %-40s%10.2f","PieceWorker Employee Total:", pieceWorkerEmployeeTotal); } // end main } // end class PayrollSystemTest
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
See the sample output
Employees processed polymorphically:
salaried employee: Lebron James
social security number: 121-11-1111
weekly salary: $1,200.00
earned $1,200.00
hourly employee: Maria Garcia
social security number: 232-22-2222
hourly wage: $26.75; hours worked: 50.00
earned $1,471.25
commission employee: David Kim
social security number: 343-33-3333
gross sales: $20,000.00; commission rate: 0.07
earned $1,400.00
base-salaried commission employee: John Miller
social security number: 454-44-4444
gross sales: $9,000.00; commission rate: 0.05; base salary: $900.00
earned $1,350.00
piece worker: Robert Green
social security number: 565-55-5555
wage per piece: $7.25; pieces produced: 700
earned $5,075.00
salaried employee: Jeff Turner
social security number: 111-11-1111
weekly salary: $800.00
earned $800.00
hourly employee: Samuel Bryant
social security number: 222-22-2222
hourly wage: $16.75; hours worked: 40.00
earned $670.00
commission employee: Avery Butler
social security number: 333-33-3333
gross sales: $10,000.00; commission rate: 0.06
earned $600.00
base-salaried commission employee: Lucas Wood
social security number: 444-44-4444
gross sales: $5,000.00; commission rate: 0.04; base salary: $300.00
earned $500.00
piece worker: Robert Williams
social security number: 555-55-5555
wage per piece: $2.25; pieces produced: 400
earned $900.00
Salaried Employee Total: 2000.00
Hourly Employee Total: 2141.25
Commission Employee Total: 2000.00
Base Plus Commission Employee Total: 1850.00
PieceWorker Employee Total: 5975.00
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
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