CASE STUDY^139
importjava.io.*; // Package for IOException
importEmployee; // Employee class
public classPayroll
{
public static voidmain(String[] args) throwsIOException
{
// Declare employees
Employee emp1;
Employee emp2;
Employee emp3;
// Instantiate employees
emp1 = newEmployee("Herman", "Herrmann", "George", 14.95);
emp2 = newEmployee("Clara", "Eames", "Julia", 16.28);
emp3 = newEmployee("Matilda", "Hagen", "Louise", 12.73);
// Output pay for each employee
System.out.println("Pay "+ emp1.name() + " $"+ emp1.pay());
System.out.println("Pay "+ emp2.name() + " $"+ emp2.pay());
System.out.println("Pay "+ emp3.name() + " $"+ emp3.pay());
// Output total pay for all employees
System.out.println("Total pay is $"+ Employee.totalPay());
}
}
The output from the application follows:
As you can see, the application code is short and simple. It includes basically just
three statements that are each repeated for the three employees. This is the goal of ob-
ject-oriented design—to produce applications that seem simple on the surface because
the complexity is hidden in the objects. Nor are the objects themselves especially com-
plex. If the algorithm for an object grows in complexity to the point that it becomes dif-
ficult to understand, it likely contains other objects that should be identified and
developed separately. In such a case, we can then simplify the object’s algorithms.