Difference between revisions of "AddressBook class lab assignment"
From WLCS
Line 5: | Line 5: | ||
'''Attributes''' | '''Attributes''' | ||
− | * a Contact array | + | * a Contact array named '''myContacts''' |
* a size variable to keep track of the size | * a size variable to keep track of the size | ||
* a MAX_SIZE variable to set the maximum size | * a MAX_SIZE variable to set the maximum size | ||
Line 21: | Line 21: | ||
*# check if the current size of the AddressBook is greater than the maximum size | *# check if the current size of the AddressBook is greater than the maximum size | ||
*#* return false if the AddressBook is full | *#* return false if the AddressBook is full | ||
− | *# | + | *# insert the new Contact in the next free element at the end of the Contacts array (myContacts[size] = newContact) |
*# increment size | *# increment size | ||
− | *# return true | + | *# return true because the new Contact was successfully added |
* void print() | * void print() | ||
*# traverse the Contact array and print out the entire AddressBook | *# traverse the Contact array and print out the entire AddressBook |
Revision as of 11:23, 22 September 2010
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 named myContacts
- 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 greater 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 (myContacts[size] = newContact)
- increment size
- return true because the new Contact was successfully added
- check if the current size of the AddressBook is greater than the maximum size
- 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
- traverse the Contact array and find the Contact with the matching first name and last name
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)
- 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?
- 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)
- The QUIT menu choice should exit the loop (HINT: use break)