Reference no: EM133860491
Question
1. Create a package called ca.bcit.comp1510.lab10
2. Create a new class in this package called Name.
3. This Name contains a String for first, middle, and last.
4. Create two constructors. One takes first, middle, last names, the second takes first, last name (middle will be set to null).
5. This Name is immutable. There are no mutators, only accessors, and the instance variables are final.
6. Validate the parameters in the constructors. Nulls are accepted for middle names, but not first names or last names. No names may be empty Strings or Strings containing nothing but whitespace. Throw an IllegalArgumentException (see slide 30 in Chapter 7) if any parameter is invalid.
7. Name implements Comparable. Add the words implements Comparable to the Name class header. The compiler will remind you that when you implement an Interface, you must implement its methods. Go ahead and do it.
8. Scroll down and you will see a new empty compareTo method. Note its parameter is another Name object. Remember the compareTo contract: Return a negative integer, zero, or a positive integer if this object is less than, equal to, or greater than the object specified as the parameter. We want to compare names or sort names COMP 1510 Bruce Link, Chris Thompson 3 of 6 alphabetically, so we can use the Strings's compareTo method. A reasonable algorithm could be something like this:
1. Compare the two last names. If they're not the same, return the value returned when you invoke the compareTo meth.