Source of BasePlusCommissionEmployee2.java


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