/**
 * An address book.
 * @author Khong Lovan
 * @author Elias Vafiadis
 * @author Anthony Nakaar
 * @author Wanlin Liu
 * version 2.0 of October, 1999
 */


public class AddressBook {

    //+--------+---------------------------------------------------------------
    //| Fields |
    //+--------+

    /* An array of names with addresses. */
    Address[] address;

    //+--------------+--------------------------------------------------------
    //| Constructors |
    //+--------------+

    public AddressBook (String fromToString)
        throws Exception {


public Address (String fromToString) 
        throws Exception {
        // Get the name
        // Get the index of the last comma,the one before the email address.
        int comma = fromToString.lastIndexOf(",");
        // If the index is invalid, throw an exception.
        if (comma == -1) {
            throw new Exception("Invalid");
        }// if
        // If the index is valid, get the name object.
        this.name = new Name(fromToString.substring(0,comma));
        // Get the address
        this.emailAddress = fromToString.substring(comma+1);
    } // Address(String)




    public AddressBook (Address[] addr) {
        this.address = addr;
    }

    //+------------+----------------------------------------------------------
    //| Extractors |
    //+------------+

    public Address[] getAddressBook() {
        return this.address;
    } //getAddressBook()

    //+-----------+---------------------------------------------------------
    //| Modifiers |
    //+-----------+    
    
    public void addAddress(Address newAddress) {
        int i = 0;
        while(address[i] != null) {
            i++;
        }
        address[i] = newAddress;
    } //addAddress(Address)

    public void removeAddress(Address theAddress) {
        int i = 0;
        try {
            while(address[i] != theAddress) {
                i++;
            }
        } //try
        catch (Exception e) {
        } //catch
        address[i] = null;
    } //removeAddress(Address)

    public String toString(Address[] address) {
        return  for (address[i] != null)
            
address.toString();
    } //toString(Address[])

} //class AddressBook

