Source of BasePlusCommissionEmployee3.java


  1: // Fig. 9.10: BasePlusCommissionEmployee3.java
  2: // BasePlusCommissionEmployee3 inherits from CommissionEmployee2 and has 
  3: // access to CommissionEmployee2's protected members.
  4: 
  5: public class BasePlusCommissionEmployee3 extends CommissionEmployee2
  6: {
  7:    private double baseSalary; // base salary per week
  8: 
  9:    // six-argument constructor
 10:    public BasePlusCommissionEmployee3( String first, String last, 
 11:       String ssn, double sales, double rate, double salary )
 12:    {
 13:       super( first, last, ssn, sales, rate );
 14:       setBaseSalary( salary ); // validate and store base salary
 15:    } // end six-argument BasePlusCommissionEmployee3 constructor
 16:    
 17:    // set base salary
 18:    public void setBaseSalary( double salary )
 19:    {
 20:       baseSalary = ( salary < 0.0 ) ? 0.0 : salary;
 21:    } // end method setBaseSalary
 22: 
 23:    // return base salary
 24:    public double getBaseSalary()
 25:    {
 26:       return baseSalary;
 27:    } // end method getBaseSalary
 28: 
 29:    // calculate earnings
 30:    public double earnings()
 31:    {
 32:       return baseSalary + ( commissionRate * grossSales );
 33:    } // end method earnings
 34: 
 35:    // return String representation of BasePlusCommissionEmployee3
 36:    public String toString()
 37:    {
 38:       return String.format( 
 39:          "%s: %s %s\n%s: %s\n%s: %.2f\n%s: %.2f\n%s: %.2f", 
 40:          "base-salaried commission employee", firstName, lastName, 
 41:          "social security number", socialSecurityNumber, 
 42:          "gross sales", grossSales, "commission rate", commissionRate,
 43:          "base salary", baseSalary );
 44:    } // end method toString
 45: } // end class BasePlusCommissionEmployee3
 46: 
 47: 
 48: /**************************************************************************
 49:  * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and               *
 50:  * Pearson Education, Inc. All Rights Reserved.                           *
 51:  *                                                                        *
 52:  * DISCLAIMER: The authors and publisher of this book have used their     *
 53:  * best efforts in preparing the book. These efforts include the          *
 54:  * development, research, and testing of the theories and programs        *
 55:  * to determine their effectiveness. The authors and publisher make       *
 56:  * no warranty of any kind, expressed or implied, with regard to these    *
 57:  * programs or to the documentation contained in these books. The authors *
 58:  * and publisher shall not be liable in any event for incidental or       *
 59:  * consequential damages in connection with, or arising out of, the       *
 60:  * furnishing, performance, or use of these programs.                     *
 61:  *************************************************************************/