public class SalariedEmployee extends Employee
1: // Fig. 10.14: SalariedEmployee.java
2: // SalariedEmployee class extends Employee, which implements Payable.
3:
4: public class SalariedEmployee extends Employee
5: {
6: private double weeklySalary;
7:
8: // four-argument constructor
9: public SalariedEmployee( String first, String last, String ssn,
10: double salary )
11: {
12: super( first, last, ssn ); // pass to Employee constructor
13: setWeeklySalary( salary ); // validate and store salary
14: } // end four-argument SalariedEmployee constructor
15:
16: // set salary
17: public void setWeeklySalary( double salary )
18: {
19: weeklySalary = salary < 0.0 ? 0.0 : salary;
20: } // end method setWeeklySalary
21:
22: // return salary
23: public double getWeeklySalary()
24: {
25: return weeklySalary;
26: } // end method getWeeklySalary
27:
28: // calculate earnings; implement interface Payable method that was
29: // abstract in superclass Employee
30: public double getPaymentAmount()
31: {
32: return getWeeklySalary();
33: } // end method getPaymentAmount
34:
35: // return String representation of SalariedEmployee object
36: public String toString()
37: {
38: return String.format( "salaried employee: %s\n%s: $%,.2f",
39: super.toString(), "weekly salary", getWeeklySalary() );
40: } // end method toString
41: } // end class SalariedEmployee
42:
43:
44: /**************************************************************************
45: * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and *
46: * Pearson Education, Inc. All Rights Reserved. *
47: * *
48: * DISCLAIMER: The authors and publisher of this book have used their *
49: * best efforts in preparing the book. These efforts include the *
50: * development, research, and testing of the theories and programs *
51: * to determine their effectiveness. The authors and publisher make *
52: * no warranty of any kind, expressed or implied, with regard to these *
53: * programs or to the documentation contained in these books. The authors *
54: * and publisher shall not be liable in any event for incidental or *
55: * consequential damages in connection with, or arising out of, the *
56: * furnishing, performance, or use of these programs. *
57: *************************************************************************/