This is an indiviual homework assignment. Please review Academic Integrity section of the class syllabus for rules on individual homework assignments.
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:
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:
private
behaviors to the PhoneRecord class, to support the public
methods. For example, we can hide the formatting of the name (first and last) and the phone number using a private method. That way, if we want to change the format in the future, we can simply update those private methods.
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
. 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
.
javac Driver.java
java Driver phoneNumbers.csv
javac Driver.java
java Driver
Submit your solution to this homework to hw3 directory of your CSCI 2300 git repo.
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.