Source of EmployeeData.java


  1: //EmployeeData.java

  3: public class EmployeeData implements Comparable<EmployeeData>
  4: {
  5:     private String firstName; // First Name
  6:     private String lastName;  // Last Name
  7:     private Integer emplID;   // Employee ID
  8:     private Integer deptNum;  // Department Number

 10:     EmployeeData
 11:     (
 12:         String firstName,
 13:         String lastName,
 14:         Integer emplID,
 15:         Integer deptNum
 16:     )
 17:     {
 18:         this.firstName = firstName;
 19:         this.lastName = lastName;
 20:         this.emplID = emplID;
 21:         this.deptNum = deptNum;
 22:     }

 24:     @Override
 25:     public int compareTo(EmployeeData otherEmpl)
 26:     {
 27:         String fullName;      // Full name, this employee
 28:         String otherFullName; // Full name, comparison employee
 29:         int comparisonVal;    // Outcome of comparison

 31:         // Compare based on department number first
 32:         comparisonVal = deptNum.compareTo(otherEmpl.deptNum);

 34:         // If in same organization, use name
 35:         if (comparisonVal == 0)
 36:         {
 37:             fullName = lastName + firstName;
 38:             otherFullName = otherEmpl.lastName + otherEmpl.firstName;
 39:             comparisonVal = fullName.compareTo(otherFullName);
 40:         }

 42:         return comparisonVal;
 43:     }

 45:     @Override
 46:     public String toString()
 47:     {
 48:         return lastName
 49:                + " "
 50:                + firstName
 51:                + "       \tID: "
 52:                + emplID
 53:                + "\t\tDept. #: "
 54:                + deptNum;
 55:     }
 56: }