Source of BasePlusCommissionEmployee4.java


  1: // Fig. 9.13: BasePlusCommissionEmployee4.java
  2: // BasePlusCommissionEmployee4 class inherits from CommissionEmployee3 and
  3: // accesses CommissionEmployee3's private data via CommissionEmployee3's 
  4: // public methods.
  5: 
  6: public class BasePlusCommissionEmployee4 extends CommissionEmployee3
  7: {
  8:    private double baseSalary; // base salary per week
  9: 
 10:    // six-argument constructor
 11:    public BasePlusCommissionEmployee4( String first, String last, 
 12:       String ssn, double sales, double rate, double salary )
 13:    {
 14:       super( first, last, ssn, sales, rate );
 15:       setBaseSalary( salary ); // validate and store base salary
 16:    } // end six-argument BasePlusCommissionEmployee4 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:       return getBaseSalary() + super.earnings();
 34:    } // end method earnings
 35: 
 36:    // return String representation of BasePlusCommissionEmployee4
 37:    public String toString()
 38:    {
 39:       return String.format( "%s %s\n%s: %.2f", "base-salaried", 
 40:          super.toString(), "base salary", getBaseSalary() );
 41:    } // end method toString
 42: } // end class BasePlusCommissionEmployee4
 43: 
 44: 
 45: /**************************************************************************
 46:  * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and               *
 47:  * Pearson Education, Inc. All Rights Reserved.                           *
 48:  *                                                                        *
 49:  * DISCLAIMER: The authors and publisher of this book have used their     *
 50:  * best efforts in preparing the book. These efforts include the          *
 51:  * development, research, and testing of the theories and programs        *
 52:  * to determine their effectiveness. The authors and publisher make       *
 53:  * no warranty of any kind, expressed or implied, with regard to these    *
 54:  * programs or to the documentation contained in these books. The authors *
 55:  * and publisher shall not be liable in any event for incidental or       *
 56:  * consequential damages in connection with, or arising out of, the       *
 57:  * furnishing, performance, or use of these programs.                     *
 58:  *************************************************************************/