Name Class

The Name class stores a first and last name only.

  1. Create the Name class, implementing the Comparable interface.
  2. Create the instance variables 'first' and 'last'.
  3. Create a constructor that takes the first and last names (Strings) as parameters.
  4. Implement the toString() method.
    • Create and return a String composed of the first and last names, separated by a single space.
  5. Implement the compareTo() method.
    • Typecast the passed Object to type Name.
    • If the last names are not equal, then return their compared value using the String object's compareTo() method.
      • Java's String object already implements the Comparable interface. The String compareTo() compares two strings lexicographically.
    • If the last names are equal, return the comparison of the first names.