AddressBook class lab assignment

From WLCS
Revision as of 10:24, 16 September 2010 by Admin (talk | contribs) (AddressBook class)

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
      • HINT: Use a loop and if statement
    • 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 (see AddressBook Menu System below)
    • 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)

AddressBook Menu System

  • You will be creating a user interface menu for use with your AddressBook
  • Open / create your AddressBook's main method
  • Print out a message that explains the program (e.g. "Welcome to YOUR_NAME's address book!")
  • Print out a menu with the following options:
(a)dd to address book
(p)rint address book
(q)uit

What would you like to do? 
  • You should prompt for input after the menu is printed. Review Media:JavaIOExample.java for examples of input/output
  • If the user inputs 'a', then print a message that says "USER SELECTED ADD"
  • If the user inputs 'p', then print a message that says "USER SELECTED PRINT"
  • If the user inputs 'q', then print a message that says "USER SELECTED QUIT"