Programming Assignment 2
A Simple Address Book
Code Review for Jade Cheng
Build Results
No errors; no warnings
Requirements Verification
All source code should be submitted in one file, and that file should be named according to the following pattern: LastFirstX.java
, where Last
is the student’s last name, First
is the student’s first name, and X
is the assignment number.
For example, student John Doe
would submit DoeJohn3.java
for programming assignment 3.
PASS.
The first lines of the submitted file should include a comment with the following information and format:
/** * A short description of the program. * * @author Last Name, First Name * @assignment CSCI 2912 Assignment X * @date Date */
PASS.
The submitted file should be emailed to ycheng@hpu.edu.
PASS.
The subject line of the email sent to the instructor should follow the pattern: [2912] assignment number
.
For example, for assignment 3, student John Doe would write “[2912] assignment 3
” as the subject line of his submission email.
PASS.
The submission email sent to the instructor should include exactly one attachment, the Java implementation file. Students should not attach any other files to their submission email.
PASS.
The implementation file must include JavaDoc for all definitions: classes, interfaces, fields, methods, enumerations, and so on.
PASS.
You will implement a Java console application that manages a simple address book.
PASS.
The address book consists of a list of contacts, and it provides methods to add, find, and print those contacts.
PASS.
Each contact consists of only a name and a phone number.
PASS.
The address book initially contains no contacts, and the application never saves or loads any data to or from permanent storage.
PASS.
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
.
PASS.
The AddressBook
should contain a collection of Contact
instances.
PASS.
The application operates in a loop.
PASS.
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.
PASS.
The menu of available commands and the prompt presented to the user appear as follows:
~ Address Book Menu ~ +-------------------------+ ADD Adds a contact FIND Finds contacts PRINT Prints contacts QUIT Quits +-------------------------+ -->
PASS.
The user may enter one of the following commands: add, find, print, or quit.
PASS.
The application ignores letter case when determining the command.
PASS.
If the user enters an invalid command, the application responds by writing “Invalid command.” and looping.
PASS.
For example, if the user enters “upload”, the application responds as follows:
--> upload
Invalid command.
PASS.
If the user enters the command add, the application prompts the user for a name and a phone number.
PASS.
The user may enter any non-empty strings for these values.
PASS.
After the user enters the two values, the application displays a message indicating the successful addition of the contact to the address book.
PASS.
The following demonstrates this interaction:
--> add NAME ---> Carl Farrell PHONE --> 808-544-0813 Added [Carl Farrell; 808-544-0813]
PASS.
If the user enters the command find, the application prompts the user for text it will use to search the address book.
PASS.
The user may enter any non-empty string for this value.
PASS.
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.
PASS.
The application ignores letter case when performing this search.
PASS.
After displaying all matching contacts, the application displays the number of contacts found.
PASS.
The following demonstrates this interaction:
--> find WHAT ---> 808 [Carl Farrell; 808-544-0813] [Curt Powley; 808-544-1145] Number of contacts found: 2
PASS.
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.
PASS.
The following demonstrates this interaction:
--> print
[Jade Cheng; 206-5059]
[Carl Farrell; 808-544-0813]
[Curt Powley; 808-544-1145]
Number of contacts: 3
PASS.
When the user enters the command quit, the application terminates without displaying any additional messages.
PASS.
The following demonstrates this interaction:
--> quit
PASS.
General Observations
Note these observations will not affect the grade.
In Java 7, it is no longer necessary to specify the type arguments of a generic when creating a new instance. For example, in Java 6, you might write this statement:
ArrayList<String> foo = new ArrayList<String>();
In Java 7, this can be written more simply as this:
ArrayList<String> foo = new ArrayList<>();
Sample Execution
$ java ChengJade2
~ Address Book Menu ~ +-------------------------+ ADD Adds a contact FIND Finds contacts PRINT Prints contacts QUIT Quits +-------------------------+ --> add NAME ---> Jade Cheng PHONE --> 206-5059 Added [Jade Cheng; 206-5059] ~ Address Book Menu ~ +-------------------------+ ADD Adds a contact FIND Finds contacts PRINT Prints contacts QUIT Quits +-------------------------+ --> add NAME ---> Carl Farrell PHONE --> 808-544-0813 Added [Carl Farrell; 808-544-0813] ~ Address Book Menu ~ +-------------------------+ ADD Adds a contact FIND Finds contacts PRINT Prints contacts QUIT Quits +-------------------------+ --> add NAME ---> Curt Powley PHONE --> 808-544-1145 Added [Curt Powley; 808-544-1145] ~ Address Book Menu ~ +-------------------------+ ADD Adds a contact FIND Finds contacts PRINT Prints contacts QUIT Quits +-------------------------+ --> print [Jade Cheng; 206-5059] [Carl Farrell; 808-544-0813] [Curt Powley; 808-544-1145] Number of contacts: 3 ~ Address Book Menu ~ +-------------------------+ ADD Adds a contact FIND Finds contacts PRINT Prints contacts QUIT Quits +-------------------------+ --> find WHAT --> pow [Curt Powley; 808-544-1145] Number of contacts found: 1 ~ Address Book Menu ~ +-------------------------+ ADD Adds a contact FIND Finds contacts PRINT Prints contacts QUIT Quits +-------------------------+ --> find WHAT --> 808 [Carl Farrell; 808-544-0813] [Curt Powley; 808-544-1145] Number of contacts found: 2 ~ Address Book Menu ~ +-------------------------+ ADD Adds a contact FIND Finds contacts PRINT Prints contacts QUIT Quits +-------------------------+ --> quit
$ java ChengJade2
~ Address Book Menu ~ +-------------------------+ ADD Adds a contact FIND Finds contacts PRINT Prints contacts QUIT Quits +-------------------------+ --> download Invalid command. ~ Address Book Menu ~ +-------------------------+ ADD Adds a contact FIND Finds contacts PRINT Prints contacts QUIT Quits +-------------------------+ --> quit
$ java ChengJade2
~ Address Book Menu ~ +-------------------------+ ADD Adds a contact FIND Finds contacts PRINT Prints contacts QUIT Quits +-------------------------+ --> AdD NAME ---> Jade Cheng PHONE --> 206-5059 Added [Jade Cheng; 206-5059] ~ Address Book Menu ~ +-------------------------+ ADD Adds a contact FIND Finds contacts PRINT Prints contacts QUIT Quits +-------------------------+ --> fInD WHAT --> jAdE [Jade Cheng; 206-5059] Number of contacts found: 1 ~ Address Book Menu ~ +-------------------------+ ADD Adds a contact FIND Finds contacts PRINT Prints contacts QUIT Quits +-------------------------+ --> QuIt
$ java ChengJade2
~ Address Book Menu ~ +-------------------------+ ADD Adds a contact FIND Finds contacts PRINT Prints contacts QUIT Quits +-------------------------+ --> --> add NAME ---> NAME ---> Jade Cheng PHONE --> PHONE --> 206-5059 Added [Jade Cheng; 206-5059] ~ Address Book Menu ~ +-------------------------+ ADD Adds a contact FIND Finds contacts PRINT Prints contacts QUIT Quits +-------------------------+ --> find WHAT --> WHAT --> 5059 [Jade Cheng; 206-5059] Number of contacts found: 1 ~ Address Book Menu ~ +-------------------------+ ADD Adds a contact FIND Finds contacts PRINT Prints contacts QUIT Quits +-------------------------+ --> quit
$ java ChengJade2 < /dev/null
~ Address Book Menu ~ +-------------------------+ ADD Adds a contact FIND Finds contacts PRINT Prints contacts QUIT Quits +-------------------------+ -->