Programming Assignment 2

A Simple Address Book

Code Review for Jade Cheng

Build Results

No errors; no warnings

Requirements Verification

REQ-SP1

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.

REQ-SP2

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.

REQ-SP3

The submitted file should be emailed to ycheng@hpu.edu.

PASS.

REQ-SP4

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.

REQ-SP5

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.

REQ-GG1

The implementation file must include JavaDoc for all definitions: classes, interfaces, fields, methods, enumerations, and so on.

PASS.

REQ-A2.1.1

You will implement a Java console application that manages a simple address book.

PASS.

REQ-A2.1.2

The address book consists of a list of contacts, and it provides methods to add, find, and print those contacts.

PASS.

REQ-A2.1.3

Each contact consists of only a name and a phone number.

PASS.

REQ-A2.2.1

The address book initially contains no contacts, and the application never saves or loads any data to or from permanent storage.

PASS.

REQ-A2.2.2

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.

REQ-A2.2.3

The AddressBook should contain a collection of Contact instances.

PASS.

REQ-A2.2.4

The application implements the UML diagram depicted in the Assignment page.

PASS.

REQ-A2.3.1

The application operates in a loop.

PASS.

REQ-A2.3.2

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.

REQ-A2.3.3

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.

REQ-A2.4.1

The user may enter one of the following commands: add, find, print, or quit.

PASS.

REQ-A2.4.2

The application ignores letter case when determining the command.

PASS.

REQ-A2.4.3

If the user enters an invalid command, the application responds by writing “Invalid command.” and looping.

PASS.

REQ-A2.4.4

For example, if the user enters “upload”, the application responds as follows:

--> upload

Invalid command.

PASS.

REQ-A2.5.1

If the user enters the command add, the application prompts the user for a name and a phone number.

PASS.

REQ-A2.5.2

The user may enter any non-empty strings for these values.

PASS.

REQ-A2.5.3

After the user enters the two values, the application displays a message indicating the successful addition of the contact to the address book.

PASS.

REQ-A2.5.4

The following demonstrates this interaction:

--> add
    NAME ---> Carl Farrell
    PHONE --> 808-544-0813

Added [Carl Farrell; 808-544-0813]

PASS.

REQ-A2.6.1

If the user enters the command find, the application prompts the user for text it will use to search the address book.

PASS.

REQ-A2.6.2

The user may enter any non-empty string for this value.

PASS.

REQ-A2.6.3

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.

REQ-A2.6.4

The application ignores letter case when performing this search.

PASS.

REQ-A2.6.5

After displaying all matching contacts, the application displays the number of contacts found.

PASS.

REQ-A2.6.6

The following demonstrates this interaction:

--> find
    WHAT ---> 808

[Carl Farrell; 808-544-0813]
[Curt Powley; 808-544-1145]

Number of contacts found: 2

PASS.

REQ-A2.7.1

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.

REQ-A2.7.2

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.

REQ-A2.8.1

When the user enters the command quit, the application terminates without displaying any additional messages.

PASS.

REQ-A2.8.2

The following demonstrates this interaction:

--> quit

PASS.

General Observations

Note these observations will not affect the grade.

  1. 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
+-------------------------+

-->