Mac os x web server - Chapter 9 Object-Oriented Programming 483 16 17 //

Chapter 9 Object-Oriented Programming 483 16 17 // Set the wage 18 public void setWage( double wagePerHour ) 19 { 20 wage = ( wagePerHour > 0 ? wagePerHour : 0 ); 21 } 22 23 // Set the hours worked 24 public void setHours( double hoursWorked ) 25 { 26 hours = ( hoursWorked >= 0 && hoursWorked < 168 ? 27 hoursWorked : 0 ); 28 } 29 30 // Get the HourlyWorker’s pay 31 public double earnings() { return wage * hours; } 32 33 public String toString() 34 { 35 return “Hourly worker: ” + super.toString(); 36 } 37 38 } // end class HourlyWorker Fig. 9.20 HourlyWorkerextends abstractclass Employee(part 2 of 2). Method main of the Test application (Fig. 9.21) begins by declaring Employee reference, ref. Each of the types of Employees is handled similarly in main, so we will discuss only the case in which maindeals with a Bossobject. 1 // Fig. 9.21: Test.java 2 // Driver for Employee hierarchy 3 4 // Java core packages 5 import java.text.DecimalFormat; 6 7 // Java extension packages 8 import javax.swing.JOptionPane; 9 10 public class Test { 11 12 // test Employee hierarchy 13 public static void main( String args[] ) 14 { 15 Employee employee; // superclass reference 16 String output = “”; 17 18 Boss boss = new Boss( “John”, “Smith”, 800.0 ); 19 Fig. 9.21 Testing the Employeeclass hierarchy using an abstractsuperclass. Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/7/01

Leave a Reply