public class BasePlusCommissionEmployee extends CommissionEmployee
1: // Fig. 10.8: BasePlusCommissionEmployee.java
2: // BasePlusCommissionEmployee class extends CommissionEmployee.
3:
4: public class BasePlusCommissionEmployee extends CommissionEmployee
5: {
6: private double baseSalary; // base salary per week
7:
8: // six-argument constructor
9: public BasePlusCommissionEmployee( String first, String last,
10: String ssn, double sales, double rate, double salary )
11: {
12: super( first, last, ssn, sales, rate );
13: setBaseSalary( salary ); // validate and store base salary
14: } // end six-argument BasePlusCommissionEmployee constructor
15:
16: // set base salary
17: public void setBaseSalary( double salary )
18: {
19: baseSalary = ( salary < 0.0 ) ? 0.0 : salary; // non-negative
20: } // end method setBaseSalary
21:
22: // return base salary
23: public double getBaseSalary()
24: {
25: return baseSalary;
26: } // end method getBaseSalary
27:
28: // calculate earnings; override method earnings in CommissionEmployee
29: public double earnings()
30: {
31: return getBaseSalary() + super.earnings();
32: } // end method earnings
33:
34: // return String representation of BasePlusCommissionEmployee object
35: public String toString()
36: {
37: return String.format( "%s %s; %s: $%,.2f",
38: "base-salaried", super.toString(),
39: "base salary", getBaseSalary() );
40: } // end method toString
41: } // end class BasePlusCommissionEmployee
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: *************************************************************************/