Assignment #2:
Arrays of Objects

Objectives: Gain experience modifying classes, setting up arrays of objects, and sorting those arrays.  

Description: This program is intended to provide you with additional experience with classes and object instantiation, as well as creating arrays of objects and manipulating them.

In order to compare two objects you must use the compareTo.  Read the linked explanation of compareTo and modify the clsName class so that it implements the Comparable interface.  You will also need to provide a compareTo method.   

Instantiate an array of clsName objects (see link), provide values for them, and then sort the array of objects in order by last name and within that by first name.  Your array can be size 5 for testing purposes.  Be sure that your program displays the output correctly even if you enter less than 5 names.  (If this were an actual application you would probably use a Vector or ArrayList.)

Sample output: 

Andrews, Darren
Roberge, Jesse
Roberge, Leslie
Roberge, Sarah
Walters, Lee

Do not remove anything from your clsName class.  Simply add the "import java.util.*;" statement, the "implements Comparable" clause, and the compareTo method.  Your form should instantiate several clsName objects, assign values to the first and last name of each, call the Arrays.sort(<arrayName>) routine, and then print the sorted results in a text box.


Also add the toString, equals, and clone methods.

Refer to the Arrays of Objects notes for assistance.

The interface should look something like this.


A demo is available here