|
| 1 | +public class PayrollSystemTest { |
| 2 | + public static void main (String[] args) { |
| 3 | + SalariedEmployee se = new SalariedEmployee("John", "Smith", "111-11-1111", 800.00); |
| 4 | + HourlyEmployee he = new HourlyEmployee("Karen", "Price", "222-22-2222", 16.75, 40); |
| 5 | + CommissionEmployee ce = new CommissionEmployee("Sue", "Jones", "333-33-3333", 10000, .06); |
| 6 | + BasePlusCommissionEmployee bpce = new BasePlusCommissionEmployee("Bob", "Lewis", "444-44-4444", 5000, .04, 300); |
| 7 | + |
| 8 | + System.out.println("Employees processed individually:"); |
| 9 | + System.out.printf("%n%s%n%s: $%,.2f%n%n", |
| 10 | + se, "earned", se.earnings()); |
| 11 | + System.out.printf("%n%s%n%s: $%,.2f%n%n", |
| 12 | + he, "earned", he.earnings()); |
| 13 | + System.out.printf("%n%s%n%s: $%,.2f%n%n", |
| 14 | + ce, "earned", ce.earnings()); |
| 15 | + System.out.printf("%n%s%n%s: $%,.2f%n%n", |
| 16 | + bpce, "earned", bpce.earnings()); |
| 17 | + |
| 18 | + Employee[] es = new Employee[4]; |
| 19 | + es[0] = se; |
| 20 | + es[1] = he; |
| 21 | + es[2] = ce; |
| 22 | + es[3] = bpce; |
| 23 | + |
| 24 | + System.out.printf("Employees processed polymorphically:%n%n"); |
| 25 | + for (Employee current : es) { |
| 26 | + System.out.println(current); |
| 27 | + if (current instanceof BasePlusCommissionEmployee) { |
| 28 | + BasePlusCommissionEmployee employee = (BasePlusCommissionEmployee) current; |
| 29 | + employee.set_base_salary(1.10 * employee.get_base_salary()); |
| 30 | + System.out.printf("new Base Salary with 10%% increase: $%,.2f%n", |
| 31 | + employee.get_base_salary()); |
| 32 | + } |
| 33 | + System.out.printf("Earned: $%,.2f%n%n", current.earnings()); |
| 34 | + } |
| 35 | + for (int j = 0; j < es.length; j++) { |
| 36 | + System.out.printf("Employee %d is a %s%n", j, es[j].getClass().getName()); |
| 37 | + } |
| 38 | + } |
| 39 | +} |
0 commit comments