Wikipedia describes CSV files as follows:
A comma-separated values (CSV) file is a delimited text file that uses a comma to separate values. Each line of the file is a data record. Each record consists of one or more fields, separated by commas. The use of the comma as a field separator is the source of the name for this file format. A CSV file typically stores tabular data (numbers and text) in plain text, in which case each line will have the same number of fields.
Although this does not seem to be standard terminology, we will use CSV-string to refer to a string that could play the role of a data record within a CSV file. That is, a CSV-string is one that is intended to be interpreted as a sequence of fields, where each pair of consecutive fields is separated by a comma character (',').
The "class-list" files maintained by the University's registrar are examples of CSV files. Each such file identifies the students who are enrolled in a particular section of a course and is accessible by the instructor of that course section. Each line/record in a class-list file is a CSV-string that describes a single student. Such a file looks something like this:
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 |
As you can infer, the fields in each line/record in a class-list file provide, respectively, a student's Royal Number, last name, first name and (possibly) middle initial, e-mail address, class, and major. The record describing Alfred E. Neuman illustrates that a field's value can be the empty string. (The last two fields in his record have that value.)
The use of the comma as the separator character is just a convention, as other characters (e.g., ;, $, #) could play the role just as well, depending upon what kind of entities are being described in the CSV file. In the ideal, one would choose as a separator a character that could not possibly occur within any field. If no such choice is possible, we can allow for the separator to occur within a field by using an escape sequence, similar to how Java uses \" to describe an occurrence of the double quote character within a literal string.
For the purposes of this assignment, we will follow convention by choosing the comma as our separator and we will assume that it cannot occur within any field.
For the purposes of testing the methods in that class, the application program CSV_Utility_Tester is provided. A sample dialog between it and a user is shown below. Input provided by the user is in boldface. If the intended behaviors of the methods are not clear to you from reading the comments describing them, you might gain clarity from examining the dialog, as it does a decent job of illustrating the various cases that can occur.
As you can infer from the dialog, we follow the convention that fields are numbered beginning with zero, so that the fields in a CSV-string having n fields are the 0th, 1st, ..., and (n−1)-st fields.
Enter CSV string: The,cat,in,the,hat Enter command (H for help):>H Examples of commands: H (display this!) Q (quit) P (print current string) # (ascertain # fields in current string) G 5 (print field #5 in current string) R 3 (remove field #3 from current string) S 2 glork (set field #2 to "glork") I 4 glork (insert "glork" as field #4) N don't,look,now (establish a new CSV-string) Enter command (H for help): P The,cat,in,the,hat Enter command (H for help): G 0 The Enter command (H for help): G 1 cat Enter command (H for help): G 2 in Enter command (H for help): G 4 hat Enter command (H for help): G 7 null Enter command (H for help): P The,cat,in,the,hat Enter command (H for help): S 1 dog The,dog,in,the,hat Enter command (H for help): i 1 cute The,cute,dog,in,the,hat Enter command (H for help): # 6 Enter command (H for help): s 0 My My,cute,dog,in,the,hatContinued in next column ... |
Enter command (H for help): s 5 car My,cute,dog,in,the,car Enter command (H for help): i 6 barked My,cute,dog,in,the,car,barked Enter command (H for help): R 1 My,dog,in,the,car,barked Enter command (H for help): r 0 dog,in,the,car,barked Enter command (H for help): R 4 dog,in,the,car Enter command (H for help): S 8 glorp dog,in,the,car Enter command (H for help): I 7 glorp dog,in,the,car Enter command (H for help): R 2 dog,in,car Enter command (H for help): R 0 in,car Enter command (H for help): # 2 Enter command (H for help): R 1 in Enter command (H for help): R 0 Enter command (H for help): i 0 Goodbye Goodbye Enter command (H for help): N see,you,later Enter command (H for help): p see,you,later Enter command (H for help): Q Goodbye. |