/* Sample program to test Employee and its subclasses. Written 1/28/97 by Kim Bruce */ public class EmployeeTester{ public static void main(String args[]){ Employee regEmp; // regular Employee ExemptEmployee exempt; // exempt Employee HourlyEmployee hourly; // hourly Employee Date exDay, hourlyDay; // Date's used to set birthdays of employees // Create and initialize exempt employee and date of birth exDay = new Date(1960,1,1); exempt = new ExemptEmployee("Jane Doe",exDay,30000); // Create and initialize hourly employee and date of birth hourlyDay = new Date(1976,12,18); hourly = new HourlyEmployee("Joe Shmoe",hourlyDay,8.00); // Figure out who makes more per week double diff = exempt.getWkPay() - hourly.getWkPay(); if (diff > 0){ System.out.println(exempt.getName() + " is paid $" + diff + " more per week than " + hourly.getName()); } else { System.out.println(hourly.getName() + " is paid $" + (-diff)+ " more per week than " + exempt.getName()); } regEmp = hourly; // Notice that an object can be assigned to a variable // representing a superclass System.out.println("regEmp " + regEmp.getName() + " is paid $" + regEmp.getWkPay() + " per week."); hourly.setHourlyPay(9.00); // Give hourly a raise // and notice that regEmp gets it as well! System.out.println("After the raise, regEmp " + regEmp.getName() + " is paid $" + regEmp.getWkPay() + " per week."); // This illustrates that assignment of objects is "sharing". Must use // "clone" if want to make a distinct copy of something. } }