Programming Assignment 2
A Simple Address Book
Objective
To develop a deeper understanding of classes and objects.
Requirements
You will implement a Java console application that manages a simple address book. The address book consists of a list of contacts, and it provides methods to add, find, and print those contacts. Each contact consists of only a name and a phone number.
The address book initially contains no contacts, and the application never saves or loads any data to or from permanent storage.
You must implement the address book as a Java class named AddressBook
, and you must implement individual contact information as a Java class named Contact
. The AddressBook
should contain a collection of Contact
instances. The following class diagram depicts this relationship:
The application operates in a loop. For each iteration, the application first shows a menu of available commands, then prompts the user to enter a command, and then finally processes that user-supplied command.
The menu of available commands and the prompt presented to the user appear as follows:
The user may enter one of the following commands: add, find, print, or quit. The application ignores letter case when determining the command. If the user enters an invalid command, the application responds by writing “Invalid command.” and looping. For example, if the user enters “upload”, the application responds as follows:
Adding Contacts
If the user enters the command add, the application prompts the user for a name and a phone number. The user may enter any non-empty strings for these values. After the user enters the two values, the application displays a message indicating the successful addition of the contact to the address book. The following demonstrates this interaction:
Finding Contacts
If the user enters the command find, the application prompts the user for text it will use to search the address book. The user may enter any non-empty string for this value. After the user enters the text, the application displays a list of all contacts that contain that text in either the contact’s name or phone number. The application ignores letter case when performing this search. After displaying all matching contacts, the application displays the number of contacts found. The following demonstrates this interaction:
Printing the Address Book
If the user enters the command print, the application prints a list of all contacts in the address book, followed by the number of contacts it printed. The following demonstrates this interaction:
Quitting
When the user enters the command quit, the application terminates without displaying any additional messages. The following demonstrates this interaction:
Examples
Output
Resources
Student Performance and Statistics
Analysis on overall student performance and coverage of requirements