March 17, 2009 / Classwork 6 – Working with ArrayLists / Due: ______
The Problem
The accompanying Java files represent an extension of the class work assignment from the previous lab period. They will compile/run as they stand, but some methods in the ContactList class are incomplete. Your assigned task is to complete those. The ContactList class has one attribute that represents an ArrayList of Contact objects. You want the main program to be able to add, delete, find, sort, and display Contact objects in the ContactList class. The program is complete and functional except for the missing implementations in the ContactList class. You should not need to modify any of the other classes.
Specifications
The following methods are the ones that are incomplete. The text beside each of the names of the methods gives some more information about what the method is to do.
· getSize ( ) – returns the number of Contacts currently in the ContactList
· add (Contact c) – add the Contact parameter to the ContactList (the ArrayList<Contact>). This operation should not succeed if c is already in the ContactList. Determine that by trying to find c. If find fails, add c. Otherwise, just return without adding anything.
· get (int n) – return the Contact object in position n of the ArrayList<Contact>
· sortByBirthDate ( ) – sorts the ArrayList<Contact> by birthDate. Note that birthDate is defined to be a Calendar object in the Contact class. The Calendar class has a compareTo method that allows one to compare two birthDates and determine their order. If X’s birthDate is less than Y’s birthDate, X was born earlier and so X is older. The compareTo is called as you should expect and it returns an integer with the meaning you should expect. The code for this sort is almost identical to the code for the existing sort method in the ContactList class – only one line needs to be modified.
· toString ( ) – overrides the toString method in the Object class. It should return a string containing all of the contacts in a displayable form. This requires very little code.
· find (Name name) – searches the ArrayList<Contact> for a Contact whose first, middle, and last names match the parameter’s first, middle, and last names. There is only a match if all 3 parts of the name match their counterparts. Return the full Contact object for the first Contact that matches. Return a null value if there are no matches.
· findOldest ( ) – return the full Contact information for the oldest Contact (the one whose birth date was earliest).
· delete (Contact c) – delete the first Contact in the ArrayList<Contact> that matches the parameter in the first, middle, and last names (only). If there are no matches, take no action.
Scoring
The getSize, add, get, and toString, and sortByBirthDate are worth 15 points each. The find, findOldest, and delete methods are worth 10 points each. A perfect project earns a grade of 105 points (a perfect score with extra credit). Submit through the Dropbox to only. Name your project 1260-xxxCW6yourname where xxx is your section number (002 or 201). Zip and submit ALL JAVA FILES (only) in the project whether you wrote them or not.
Classwork 6 - ArrayListsPage 1