Class AddressBook

java.lang.Object
  extended byjava.util.Observable
      extended byAddressBook
All Implemented Interfaces:
java.io.Serializable

public class AddressBook
extends java.util.Observable
implements java.io.Serializable

An object of this class maintains the collection of Person objects that constitute an address book

See Also:
Serialized Form

Constructor Summary
AddressBook()
          Constructor - create a new, empty address book
 
Method Summary
 void addPerson(java.lang.String firstName, java.lang.String lastName, java.lang.String address, java.lang.String city, java.lang.String state, java.lang.String zip, java.lang.String phone)
          Add a new Person to the collection
 boolean getChangedSinceLastSave()
          Find out whether this address book has been changed since last open / save
 java.io.File getFile()
          Get the File this address book was most recently read from or saved to
 java.lang.String getFullNameOfPerson(int index)
          Provide the full name of a person
 int getNumberOfPersons()
          Get the current size of the collection
 java.lang.String[] getOtherPersonInformation(int index)
          Provide the rest of the current information about a person
 java.lang.String getTitle()
          Get the title of this address book - based on the most recently used file
 void printAll()
          Print the collection of persons in order.
 void removePerson(int index)
          Remove a specific person from the collection
 void setChangedSinceLastSave(boolean changedSinceLastSave)
          Record a change in the saved status of this address book
 void setFile(java.io.File file)
          Set the File this address book was most recently read from or saved to
 void sortByName()
          Sort the collection by name
 void sortByZip()
          Sort the collection by ZIP
 void updatePerson(int index, java.lang.String address, java.lang.String city, java.lang.String state, java.lang.String zip, java.lang.String phone)
          Update stored information about a person
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AddressBook

public AddressBook()
Constructor - create a new, empty address book

Method Detail

getNumberOfPersons

public int getNumberOfPersons()
Get the current size of the collection

Returns:
the number of persons in the collection

addPerson

public void addPerson(java.lang.String firstName,
                      java.lang.String lastName,
                      java.lang.String address,
                      java.lang.String city,
                      java.lang.String state,
                      java.lang.String zip,
                      java.lang.String phone)
Add a new Person to the collection

Parameters:
firstName - the person's first name
lastName - the person's last name
address - the person's address
city - the person's city
state - the person's state
zip - the person's zip
phone - the person's phone

getFullNameOfPerson

public java.lang.String getFullNameOfPerson(int index)
Provide the full name of a person

Parameters:
index - the position of the desired person
Returns:
the person's full name, in a form suitable for displaying or printing

getOtherPersonInformation

public java.lang.String[] getOtherPersonInformation(int index)
Provide the rest of the current information about a person

Parameters:
index - the position of the desired person
Returns:
an array of Strings, each containing one piece of stored information about this person. The person's name is _not_ included, since this is not changeable.

updatePerson

public void updatePerson(int index,
                         java.lang.String address,
                         java.lang.String city,
                         java.lang.String state,
                         java.lang.String zip,
                         java.lang.String phone)
Update stored information about a person

Parameters:
index - the position of the desired person
address - the person's new address
city - the person's new city
state - the person's new state
zip - the person's new zip
phone - the person's new phone

removePerson

public void removePerson(int index)
Remove a specific person from the collection

Parameters:
index - the position of the desired person

sortByName

public void sortByName()
Sort the collection by name


sortByZip

public void sortByZip()
Sort the collection by ZIP


printAll

public void printAll()
Print the collection of persons in order.


getFile

public java.io.File getFile()
Get the File this address book was most recently read from or saved to

Returns:
the most recent File - if any - null if none

getTitle

public java.lang.String getTitle()
Get the title of this address book - based on the most recently used file

Returns:
the title of this address book - "Untitled" if none

setFile

public void setFile(java.io.File file)
Set the File this address book was most recently read from or saved to

Parameters:
file - the file just used to read or save this object

getChangedSinceLastSave

public boolean getChangedSinceLastSave()
Find out whether this address book has been changed since last open / save

Returns:
true if this address book has been changed since the last open / save; false if not

setChangedSinceLastSave

public void setChangedSinceLastSave(boolean changedSinceLastSave)
Record a change in the saved status of this address book

Parameters:
changedSinceLastSave - the new status