public class FullName implements java.lang.Comparable { 
  private String firstName;
  private String lastName;

  public FullName(String first, String last) {
    firstName = first;
    lastName = last;
  } // end constructor

  public int compareTo(Object rhs) {
  // Precondition: The object rhs should be a Fullname object
  // Postcondition: Returns 0 if all fields match
  //    if lastName equals rhs.lastName and 
  //    firstName is greater than rhs.firstName.
  // Returns -1 if lastName is less than rhs.lastName or 
  //    if lastName equals rhs.lastName and 
  //    firstName is less than rhs.firstName
  // Throws: ClassCastException if the rhs object is not a Fullname
  // object.

  // Throws ClassCastException if rhs cannot be cast to Fullname
    FullName other = (FullName)rhs;

    if (lastName.compareTo(((FullName)other).lastName)==0){
      return firstName.compareTo(((FullName)other).firstName);
    } 
    else {
      return lastName.compareTo(((FullName)other).lastName);
    } // end if
  } // end compareTo
} // end class FullName
