Source of SalariedEmployee.java


  1: // Fig. 10.5: SalariedEmployee.java
  2: // SalariedEmployee class extends Employee.
  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; override abstract method earnings in Employee
 29:    public double earnings()
 30:    {
 31:       return getWeeklySalary();
 32:    } // end method earnings
 33: 
 34:    // return String representation of SalariedEmployee object
 35:    public String toString()
 36:    {
 37:       return String.format( "salaried employee: %s\n%s: $%,.2f", 
 38:          super.toString(), "weekly salary", getWeeklySalary() );
 39:    } // end method toString
 40: } // end class SalariedEmployee
 41: 
 42: 
 43: /**************************************************************************
 44:  * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and               *
 45:  * Pearson Education, Inc. All Rights Reserved.                           *
 46:  *                                                                        *
 47:  * DISCLAIMER: The authors and publisher of this book have used their     *
 48:  * best efforts in preparing the book. These efforts include the          *
 49:  * development, research, and testing of the theories and programs        *
 50:  * to determine their effectiveness. The authors and publisher make       *
 51:  * no warranty of any kind, expressed or implied, with regard to these    *
 52:  * programs or to the documentation contained in these books. The authors *
 53:  * and publisher shall not be liable in any event for incidental or       *
 54:  * consequential damages in connection with, or arising out of, the       *
 55:  * furnishing, performance, or use of these programs.                     *
 56:  *************************************************************************/