Assignment 2

(Version 1.0)

Due: 11:30 AM on Wednesday, October 25, 2000


Overview

Consider a file-based database system. Each database is encoded as a file that has a fixed number of columns of data; call each line of this file an entry, and each column-item within a line a field. The fields are numbered starting at 1 from left to right, and each line in the file has the same number of fields (though each line or field does not necessarily have the same length). The fields within each line are delimited by one of a set of separator characters. For example, consider the following such file with field-delimiter character '#':

This file has 4 entries and 3 fields per entry; field 2 of entry 3 is "Schweitzer, Albert" and field 3 if entry 4 is "Physics". Such database files are known as flat files.

In this assignment, you will implement both a generic flat file class and a class that uses this generic class to implement a password database.

Specification

You must implement the following two Java classes: You will be given the following:

Fill in missing details and fully comment the code in FlatFile.java; places where you need to fill in code are denoted by the inline comment "*** PERFORM MAGIC HERE ***". All other given Java files are complete as they are. You will have to write your own file containing the class-definition of PasswordDb as described above.



IMPORTANT: As your submitted code will be tested using programs that assume the classes and methods described above, the classes in your submitted code must be named and all methods in these classes must be defined EXACTLY as specified above. Submitted code not conforming to these specifications will not be tested and marks will be deducted accordingly.



Hints

Separating a line into fields is very easy using the Java class StringTokenizer; in particular, note that there is a version of that class's constructor that allows you to specify a string of token-delimiter characters (sounds like string fieldSep to me).

Adding a line to a file is much easier if writing is done using the append version of the constructor for the FileWriter class.

Various methods in class File, e.g., renameTo, delete, are very handy not only for querying files existence or permissions but also for performing LINUX shell operations on files like renaming or deletion.

Each PasswordDb object will should have an associated flatfile object.

Remembering whether or not a PasswordDb object has been loaded or not can be done very easily using a private boolean variable loaded; such a variable should be initialized to false when the object is created, its value modified accordingly by methods load and save, and its value checked by all other methods as necessary.

You may use any data structures you wish to implement the storage for the password database inside a PasswordDb object. May I suggest using a pair of vectors to store the passwords and names, respectively.

Compiling and Running

See appropriate web pages for instructions on compiling and running Java programs.

Submitting Your Programs

Please submit your program files FlatFile.java and PasswordDb.java using system program submit-assignment by the due date. No hardcopies of these files need to be passed in to me. NOTE: If you are using non-standard classes for input or output, e.g., Keyboard, EasyReader, please submit files containing theses class definitions along with the requested Java files.


Additional Notes:


Created: October 10, 2000
Last Modified: October 13, 2000