AddressBook class lab assignment

From WLCS
Revision as of 11:02, 17 September 2008 by Admin (talk | contribs) (AddressBook class)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

AddressBook class

  • The objective of this assignment will be to design and implement an address book
  • Your address book will allow you to add, remove, and search for contacts
  • The first version of our address book will use a Contact array, but future versions of AddressBook will not

Attributes

  • a Contact array
  • a size variable to keep track of the size
  • a MAX_SIZE variable to set the maximum size

Constructors

  • a default constructor
    • assign MAX_SIZE to 20
    • assign the Contact array to a new Contact array of MAX_SIZE elements
    • set the size variable to 0

Methods

  • getter methods for the attributes
  • setter methods for the attributes (do NOT make a setter for MAX_SIZE)
  • boolean add(Contact newContact)
    • check if the current size of the AddressBook is still less than the maximum size
      • return false if the AddressBook is full
    • insert the new Contact in the next free element at the end of the contacts array
    • increment size
    • return true if the new Contact was successfully added
  • void print()
    • traverse the Contact array and print out the entire AddressBook
  • Contact find(String fn, String ln)
    • traverse the Contact array and find the Contact with the matching first name and last name
    • return the Contact with the matching first name and last name
    • return null if the Contact is not found

AddressBook Main

  • Create a new file named AddressBookMain
  • Create a new main method to test your AddressBook
  • Your AddressBook demo should use a menu system you create
    • When the user selects to ADD a Contact, you should prompt them for a first name, last name, phone, and address.
    • You should then create a new Contact
    • Add the Contact to your AddressBook using the AddressBook's add() method
  • The PRINT menu choice should print the entire AddressBook using the print() method
  • Make sure your menu runs again after the user makes a choice (HINT: use a loop somewhere)