This week you will continue implementing the Address Book application that you have designed. You will be implementing three classes that will allow you to view your address book in a window.
Hopefully, your design includes a class to represent a list of contacts. You might have called this class something like ContactList. This class should have an attribute of type String for the list name, and an attribute for the list of contacts. A good type for the list attribute is ArrayList<Contact> (assuming Contact is the name of your class for address book entries).
Your design should also have included a class for the address book, e.g. AddressBook, and a class for displaying an address book in a window, e.g. AddressBookWindow. Your AddressBook class probably contains an attribute for a list of contact lists. A good type for this attribute would be ArrayList<ContactList>. The AddressBookWindow class should have an attribute of type AddressBook as well as the attributes that are required for the GUI.
If your design is much different from what is described above, you should consult with your lab instructor on how to proceed.
ArrayLists are objects that maintain lists of other objects. For example, an object
of type ArrayList<Contact> is used to maintain a list of Contact
objects. The ArrayList class has many methods to manage a list including methods to
add and remove objects from the list.
For example, we could add and remove some contacts from a contact list as follows:
// Create a contact list
ArrayList<Contact> contactList = new ArrayList<Contact>();
// Create some contact objects
Contact c1 = new Contact(...); // pass whatever parameters needed to initialize the contact
Contact c2 = new Contact(...);
Contact c3 = new Contact(...);
// Add the contacts to the list
contactList.add(c1);
contactList.add(c2);
contactList.add(c3);
// Remove one of the contacts from the list
contactList.remove(c2);
Now suppose we want to print out the nickname of each contact on the list (assuming you have
defined a getNickname method in your Contact class). We could accomplish this
using a loop, as follows:
// Access each contact on the list, and print its nickname on the console
for (Contact c: contactList) {
System.out.println(c.getNickname());
}
As you complete each exercise, make sure that your requirement and design documents are kept consistent with what you have done. You may need to customize the exercises somewhat depending on your particular design. If in doubt, consult your lab instructor.