For this lab you can work with a partner.
The main aim of this lab is to introduce you to the concept of object interaction, loops, and collections like ArrayList. Make sure you have ArrayList documentation open. You can get it here: http://java.sun.com/j2se/1.5.0/docs/api/
This will help you understand different methods you are using.
For this lab you will implement two classes: Person and AddressBook that will store a collection of Person.
Class Design
Person
The Person class will have two private fields of type string. The fields are: person’s name and his address. Each field needs a mutator and an accessor method also known as setters and getters. The class should have two constructors. The signatures are shown below.
Person Class Interface
public Person();
public Person(String name, String address);
public void setName(String name);
public void setAddress(String address);
public String getName();
public String getAddress();
AddressBook
Your class AddressBook will have one private field called addressBook of type ArrayList. It will need a constructor, a method called addAddress(), and a method called showAddress(int addressNumber). The signatures for these methods are specified in the interface along with what should they do. We have multiple ways to browse through the address book collection, this is to get familiar with different types of loops.
Note: For each method you will have to figure out from the documentation which method to use from the ArrayList class.
public
AddressBook();
public void
addAddress( Person newPerson );
public void
listAddressesWhile();
public void listAddressesFor(); // will display a list of all the persons in collection along with their names and addresses using a for loop
public void listAddressesDoWhile(); // will display a list of all the persons in collection along with their names and addresses using a Do-While loop. Make sure you don't get an exception for an empty list.
public void listAddressesIterator(); // will display a list of all the persons in collection along with their names and addresses using an Iterator
public string
showAddress( int addressNumber );
public string
removePerson (String personName);
Please document your code.
Absolutely Necessary!