CMPS 134 Fall 2024
Prog. Assg. 5: CSV Query Application Revised
Due: Monday, November 4, 2024

Background

It is common for a CSV file to contain a "header record" as the first line in the file. Such a header record specifies the titles of the corresponding fields appearing in the records that follow. Consider this CSV file:

Example Class-List File
ID,Last,First,Email,Year,Major
R01234567,Brown,Charlie,charlie.brown@scranton.edu,Freshman,Computer Science
R45678912,Dinkley,Velma,velma@scoobydoo.com,Senior,Paranormal Crime
R55555555,Neuman, Alfred E.,alfred.neuman@madmagazine.com,,
R19283745,Van Pelt,Linus,linus.vanpelt@scranton.edu,Sophomore,Theology
R98765432,Van Pelt,Lucy,lucy.vanpelt@scranton.edu,Junior,Chemistry

Note that the header record, like each of the following data records, is in CSV format.

Specification

# java CSVQueryR class-list.txt
Enter query:>Last
Brown

Enter query:>First
Charlie

Enter query:>Major
Computer Science

Enter query:>N

Enter query:>First
Velma

Enter query:>2
--->Invalid query; try again.

Enter query:>Height
--->Invalid query; try again.

Enter query:>Year
Senior

Enter query:>Q
Done!
You are to revise the Java application CSVQuery, which is a (correct, one hopes) solution to Prog. Assg. 3. Your revised application should be named CSVQueryR, and its behavior should be different from CSVQuery in that it "expects" the "queries" submitted to it to be field titles rather than field position numbers. This change in behavior should be implemented by making full and appropriate use of the Java "instance" class CSV_String.

Consider the user/program interaction shown to the right, where the input file (whose name is provided to the program via a command-line argument) is the example class-list file shown above. As a second sample data file, LadyRoyals2023.txt is provided.

You may find the CSV_String_ClientR program useful to you in gaining a fuller understanding of the CSV_String class.

Extra Credit

For a few extra points, you are encouraged to enhance the program so that it responds to the command 'T' by displaying the field titles (in the form of a CSV-string). For the example class-list file, that command should produce as output the line

ID,Last,First,Email,Year,Major

Submission of Program

As usual, use the appropriate Brightspace dropbox to submit your completed Java source program, which must be in a file named CSVQueryR.java. (Do not submit the corresponding .class file, or any other file for that matter.)

Note that you can submit more than one time. Hence, if, after submitting, you improve your program (e.g., by fixing logic errors or by enhancing your comments), you should submit the newer version, but the name of the class and the file should not be changed!

The CSVQuery program that was provided to you (see link above) includes comments describing its behavior. As your revised program should not have the same behavior, you are expected to have modified those comments accordingly. You should also modify, as appropriate, the other comments present in the given program, in particular to identify yourself as an author and others who helped you. Also mention any defects of the program. Consider this to be a template that you are expected to follow in all subsequent assignments.