Homework 2

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.

Project Overview

In this homework, you will implement a few classes that you will need for a larger project, which will be assigned in homework 3. To help you understand the big picture, the larger project is described in this section, while Homework 2 Description section provides the specifics of homework 2.

We want to design and implement a program that keeps track of phone number records. Suppose we have a CSV file with a list of people and their phone numbers. Given this CSV file, we want to be able to answer the following questions:

To implement this project, we'll need to do some preliminary design: a set of classes that we'll use to represent and manipulate the data. Let's consider some questions:

Homework 2 Description

Our first step toward designing this project is to create a mechanism for reading phone number records from a CSV file. Since reading phone recrods from a CSV file (or any other type of file or database) is a concern that is completely separate from searching through the records, we'll have a dedicated class, PhoneRecordReaderCSV, for doing the reading from CSV file. This class is responsible for reading all the phone records from the file, whose name is provided in the constructor. If it cannot read from the provided file, it should print "Could not read from <FILE_NAME>" followed by the error message provided in the exception. This class should not throw any exceptions. I provided a skeleton PhoneRecordReaderCSV.java for you to start with. Implement the methods outlined in this skeleton. Do not change the names, return types, or parameters of the methods provided. Feel free to add anything you need to this class.

The PhoneRecordReaderCSV class uses a PhoneRecord class, which encapsulates the data in each line of the csv file. Specifically, it encapsulates the first name, last name, and phone number of each record. I provided a skeleton PhoneRecord.java code for you to start with. Implement the methods outlined in this skeleton. Do not change the names, return types, or parameters of the methods provided. Feel free to add anything you need to this class. Note, that the comments of this class skeleton provide more specific instructions about what is expected of each method. Make sure to read these comments and follow those instructions.

Write a Driver class that contains the main method, which should:

  1. accept one command line argument - the name of the CSV file
  2. Create an instance of the PhoneRecordReaderCSV object, using the file name provided at command line.
  3. Get an ArrayList of phone records from the PhoneRecordReaderCSV object and print them to the terminal (one per line). What's a convenient way to print a human readable version of an object?
An example usage of your Driver clas is shown below:
javac Driver.java
java Driver phoneNumbers.csv
An example csv file can be found here. You should test your application with this sample file. In addition to this, you should do more testing to ensure that:

Submitting your solution

Submit your solution to this homework to hw2 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 to 2 points: No - 0, Somewhat - 1, Yes - 2. The sum of these points will be your grade for this homework.
  1. Does your Driver utilize the command line argument containing input file name?
  2. Does your Driver gracefully handle the case when no command line argument is provided?
  3. Does your application gracefully handle non-existing input files?
  4. Does your PhoneRecordFromCSV class properly retrieve all records defined in the input file?
  5. Does getPhoneNumber() of the PhoneRecord class return a properly formatted phone number?
  6. Does getLastName() of the PhoneRecord class return a properly formatted last name?
  7. Does your application gracefully (without crashing) handle bad input (consider a csv file that does not have all three required fields for a phone number record)?
  8. Did you follow good programming practices (code indentation, variable names, etc)?