Source of Employee.java


  1: // Fig. 10.13: Employee.java
  2: // Employee abstract superclass implements Payable.
  3: 
  4: public abstract class Employee implements Payable
  5: {
  6:    private String firstName;
  7:    private String lastName;
  8:    private String socialSecurityNumber;
  9: 
 10:    // three-argument constructor
 11:    public Employee( String first, String last, String ssn )
 12:    {
 13:       firstName = first;
 14:       lastName = last;
 15:       socialSecurityNumber = ssn;
 16:    } // end three-argument Employee constructor
 17: 
 18:    // set first name
 19:    public void setFirstName( String first )
 20:    {
 21:       firstName = first;
 22:    } // end method setFirstName
 23: 
 24:    // return first name
 25:    public String getFirstName()
 26:    {
 27:       return firstName;
 28:    } // end method getFirstName
 29: 
 30:    // set last name
 31:    public void setLastName( String last )
 32:    {
 33:       lastName = last;
 34:    } // end method setLastName
 35: 
 36:    // return last name
 37:    public String getLastName()
 38:    {
 39:       return lastName;
 40:    } // end method getLastName
 41: 
 42:    // set social security number
 43:    public void setSocialSecurityNumber( String ssn )
 44:    {
 45:       socialSecurityNumber = ssn; // should validate
 46:    } // end method setSocialSecurityNumber
 47: 
 48:    // return social security number
 49:    public String getSocialSecurityNumber()
 50:    {
 51:       return socialSecurityNumber;
 52:    } // end method getSocialSecurityNumber
 53: 
 54:    // return String representation of Employee object
 55:    public String toString()
 56:    {
 57:       return String.format( "%s %s\nsocial security number: %s", 
 58:          getFirstName(), getLastName(), getSocialSecurityNumber() );
 59:    } // end method toString
 60: 
 61:    // Note: We do not implement Payable method getPaymentAmount here so  
 62:    // this class must be declared abstract to avoid a compilation error.
 63: } // end abstract class Employee
 64: 
 65: 
 66: /**************************************************************************
 67:  * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and               *
 68:  * Pearson Education, Inc. All Rights Reserved.                           *
 69:  *                                                                        *
 70:  * DISCLAIMER: The authors and publisher of this book have used their     *
 71:  * best efforts in preparing the book. These efforts include the          *
 72:  * development, research, and testing of the theories and programs        *
 73:  * to determine their effectiveness. The authors and publisher make       *
 74:  * no warranty of any kind, expressed or implied, with regard to these    *
 75:  * programs or to the documentation contained in these books. The authors *
 76:  * and publisher shall not be liable in any event for incidental or       *
 77:  * consequential damages in connection with, or arising out of, the       *
 78:  * furnishing, performance, or use of these programs.                     *
 79:  *************************************************************************/