/* * @author Robert Russell * @updated by VH * @ updated by Ben Hample, Greg Krywicki, Robert Russell (12/18/07) * @date 9/22/07 * Class Employee contains employee's name (string) and age (int) * Class Employee provides the following methods: * Class constructor (string, age) * getAge * getName * setAge * setName * isOlder * isYounger * sameAge * toString */ public class Employee implements Comparable { String name; int age; /** * Creates a new instance of Employee * @param a String that represents the name of the Employee * @param an int that represents the Employee's age **/ public Employee(String name, int age) { this.name = name; this.age = age; } /** * @return an int, which the age of this Employee **/ public int getAge() { return age; } /** *@return a String, which the name of this Employee **/ public String getName() { return name; } /** *@return true if this employee is older than the * employee passed into the method **/ public Boolean isOlder(Employee e) { return (age > e.getAge()); } /** *@return true if this employee is younger than the * employee passed into the method **/ public Boolean isYounger(Employee e) { return (age < e.getAge()); } /** *@return true if this employee is same age as * the employee passed into the method **/ public Boolean sameAge(Employee e) { return (age == e.getAge()); } /** *@return a String that displays the Employee's name and age **/ public String toString() { String info = name.trim() + ", age " + age; return info; } public void setName(String name) { this.name = name; } /* * Purpose: Implementation of the compareTo method from the * Comparable interface in order to compare employee names * Pre: None * Post: None * In: An object of the type Employee * Out: If this employee's name is less than argument's name, return -1 * If it greater, then return one. If they are equal, return 0. */ public int compareTo(Object e) { Employee emp = (Employee) e; if(this.getName().compareTo(emp.getName()) > 0) { return 1; } else if(this.getName().compareTo(emp.getName()) < 0) { return -1; } else { return 0; } } }