Name Class
The Name class stores a first and last name only.
- Create the Name class, implementing the Comparable interface.
- Create the instance variables 'first' and 'last'.
- Create a constructor that takes the first and last names (Strings) as parameters.
-
Implement the toString() method.
- Create and return a String composed of the first and last names, separated by a single space.
-
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.