/** * File CISC370HOME/example-progs/grossPay/Name.java * * A class for Name objects. */ package grossPay; import corejava.Console; // for readWord() class Name { /** * Public constructors */ Name( String first, String last ){ firstName = first; lastName = last; } /** * Private instance variables */ private String lastName, firstName; /** * Public instance methods */ public String getLastName(){ return lastName; } public String getFirstName(){ return firstName; } public void read(){ // Read name from console firstName = Console.readWord(); lastName = Console.readWord(); } public String toString(){ // Overrides Object.toString() return firstName + " " + lastName; } /** * Checks for equality of two Names. Overrides Object.equals(). */ public boolean equals(Object other){ return (firstName.equals( ((Name)other).firstName ) && lastName.equals( ((Name)other).lastName ) ); } /** * Compares for alphabetical order of two Names. Analogous to * String.compareTo(). */ public int compareTo(Name other){ int ans = lastName.compareTo(other.lastName); if ( ans != 0 ) return ans; else return firstName.compareTo(other.firstName); } }