Homework 3

Learning Objectives

In this homework, you will apply the concepts you learned in class to reinforce your understanding of:

Homework Policy

This is an indiviual homework assignment. Please review Academic Integrity section of the class syllabus for rules on individual homework assignments.

Description

In homework 2 you designed an implemented classes that you will need for homework 3. These classes encapsulate some informatoion and functionality. Specifically:

We will now add a few more classes to design and implement a searchable phone book. When the program starts up, phone number records get loaded and the user is presented with an option to search the records. The user can enter a search term and our program will search its records for a match. Note, that the user can enter either a first name, a last name, or a phone number. Regardless of which value the user entered, we must find all matches. Consider an example where the phone records contain the following data:

The user enters 'mary' as a search term. Your program will search its records, find and display the record with 'mary' in it
MARY SWANSON 9999999999

If the user enters '5555555555', your program should search its records, find and display the two records whose phone number matches:
LLOYD CHRISTMAS 5555555555
HARRY DUNNE 5555555555

Note, that your application should match names (first name and last name) regardless of capitalization: mary, MARY, Mary, and MaRy are all considered a match. Similarly, your application should match phone numbers regardless of whether dashes were used: 5555555555, 555-555-5555, and 555-5555555 are all considered a match.

Let's revisit some of the questions we raised in homework 2:

In addition to being able to read the phone records from a CSV file, we want to give the user an ability to enter data manually from the terminal. If the user does not specify a file name in a command line argument (when the application is started), then we'll have the user enter the data manually from the terminal. If the user does provide a file name as a command line argument, we'll load the data from the csv file. This is were inheritance and abstraction will help us simplify the design. Regardless of whether we are loading the data from a file or from a terminal, the end goal is the same - to obtain the phone records for our phone book. We can view this as two different implementations of the same behavior: one implementation gets data from a csv file and the other one gets it from the terminal. The phone book does not care how the data gets loaded, as long as it gets loaded. Therefore, we can create an abstract class, PhoneRecordReader with an abstract function public abstract ArrayList getRecords(). Now, you can add a PhoneRecordReaderTerminal class, as a subclass of PhoneRecordReader. Its implementation of the getRecords() method is to prompt the user to enter first name, last name, and phone number and save this information as a phone record. Now, if you update the PhoneRecordReaderCSV class from homework 2 to extend PhoneRecordReader, your PhoneBook class can interact with the two different record readers at the abstract level of PhoneRecordReader. Consider the design shown below.

In this design, the PhoneBook class loads records using a PhoneRecordReader. Which concrete implementation of the PhoneRecordReader will be used will depend on whether the user passes an input file name as a command line argument. The Driver of this program will need to instantiate either a PhoneRecordReaderCSV or a PhoneRecordReaderTerminal class and pass it to the PhoneBook.

Example Run using Data From File

An example usage of your Driver class with a command line argument is shown below:
javac Driver.java
java Driver phoneNumbers.csv

Example Run using Data from Terminal

An example usage of your Driver class without a command line argument is shown below:
javac Driver.java
java Driver

Submitting your solution

Submit your solution to this homework to hw3 directory of your CSCI 2300 git repo.

Grading

All submitted code must compile. Code that does not compile will receive a grade of zero. I will be compiling your submissions on hopper.slu.edu with the following command:
javac Driver.java To grade your programs, I will use the list of questions below. Each question can score you from 0 or 3 points: No - 0, Yes - 3. The sum of these points will be your grade for this homework.
  1. Does your application support loading phone number records from a csv file?
  2. Does your program support entering phone number records from the terminal?
  3. Does your application correctly find all records for a given first name?
  4. Does your application correctly find all records for a given last name?
  5. Does your application correctly find all records for a given phone number?
  6. Does your application correctly handle search by first name, regardless of capitalization?
  7. Does your application correctly handle search by last name, regardless of capitalization?
  8. Does your application correctly handle search by phone number, regardless of the dashes?
  9. Does your application utilize abstract class to handle two ways of loading data?
  10. Did you follow good programming practices (code indentation, variable names, etc)?