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.
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
PayrollSystemTester.java package payrollsystemtester;
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<>(); ArrayList
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
----------------------------------------------------------------------------------------------------------------------------
output
run: Employees processed polymorphically:
Salaried Employee :Lebron James social security number:121-11-1111 weekly salary :1200.0 earned $1,200.00
Hourly Employee :Maria Garcia social security number:232-22-2222 hourly wages :26.75 hours worked :50.0 earned $1,471.25
Commission Employee :David Kim social security number:343-33-3333 gross sales :20000.0 commission rate :0.07 earned $1,400.00
base-salaried commission employee :John Miller social security number:454-44-4444 gross sales :9000.0 commission rate :0.05 base salary :900.0 earned $1,350.00
Piece worker :Robert Green social security number:565-55-5555 wage per piece :7.25 pieces produced :700.0 earned $5,075.00
Salaried Employee :Turner Jeff social security number:111-11-1111 weekly salary :800.0 earned $800.00
Hourly Employee :Samuel Bryant social security number:222-22-2222 hourly wages :16.75 hours worked :40.0 earned $670.00
Commission Employee :Avery Butler social security number:333-33-3333 gross sales :10000.0 commission rate :0.06 earned $600.00
base-salaried commission employee :Lucas Wood social security number:444-44-4444 gross sales :5000.0 commission rate :0.04 base salary :300.0 earned $500.00
Piece worker :Robert Williams social security number:555-55-5555 wage per piece :2.25 pieces produced :400.0 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