Homework 4 Programming Part (25 points)

In this question you are required to use your red-black tree ADT from Assignment 2 and your hash table from Assignment 3 to create a database of students. The database should be indexable by student number and by student name. You can assume that there are no students with the same number but different names.

Most of the code necessary to handle the data persistence and the user interface is already written in the files provided to you. The user interfaces with the database through the command line argument of your program, namely, 'studentDB'. In particular, 

Your job

Step 1

Before writing any lines of code, make sure that you have read and understood all the code provided. You can use JavaDoc to create an HTML documentation of the code in the files (this is not really necessary). All the functions have comments that explain what is expected from them.

If you do not know what JavaDoc is, go to http://www.cs.toronto.edu/~dianeh/148/handbook/javadoc/

Note: if your RedBlackTree and HashTable classes are already working well, you will not need to do much coding for the programming question in this assignment. If it looks otherwise, it probably means that you misunderstood what is to be done. If only one of your RedBlackTree and HashTable classes is working well, then do the assignment with that one and go back to the other one if you have time. If neither is working well, get (a possibly simplified version of) one of them working. For example, you may use BST trees instead of RedBlackTrees, or you may use hashing with closed addressing in a fixed-sized table.

Step 2

Modify your red-black tree and your hash table to make it work as required by the updated Indexable interface. In this assignment, the Indexable interface is designed to represent a container of generic Objects. The new requirements will not affect your old code much, but you will have to do a few modifications to it.

In particular, to obtain the key of an object representing a record, you will need to implement the function "Comparable getRecordKey(Object x)." This is already done for the red-black tree (see RecordRBTDictionary.java and StudentNameRBTDictionary.java). You will have to modify your old code so that it calls getRecordKey() whenever it needs a record's key. In addition, since the returned key is an object implementing the Java interface Comparable, you will have to modify your code to make comparisons of keys using the function compareTo() (NOTE: the classes Integer and String already implement the interface Comparable). e.g.,

Integer a = new Integer(10);
Integer b = new Integer(20);

if (a.compareTo(b) == 0)
// a and b are equal.
else if (a.compareTo(b) < 0)
// a is smaller than b.
else
// a is greater than b.

Suggestion: do not use your old red-black tree and hash table classes (and related classes). Instead, migrate your old code to the corresponding new classes, which already implement the updated interface Indexable and the Java interface Serializable (necessary for I/O operations with the objects), and have comments that will help you do your work. You will note that the classes RedBlackTree and HashTable do not implement all the functions in the Indexable interface. In particular, they do not implement getRecordKey() and validateRecordClass(). This is so because they are meant to work with generic objects. Therefore, RedBlackTree and HashTable are declared as abstract classes (ie, you cannot create an object of these classes). The specialized classes that inherit from RedBlackTree or HashTable are the ones in charge of implementing the remaining functions of the interface Indexable. In addition, the function hashKey() in HashTable is now an abstract function, and so it must be implemented in the classes that inherit from HashTable.

Step 3

The command

Java studentDB student.db -create HT

must create dictionaries implemented by hash tables. You must add a few lines to enable this functionality.

Your main job is to make all the database commands (create, insert, delete, and search) work for databases implemented by both red-black trees and hash tables. However, it is more important to achieve full functionality with either one of these ADTs than partial functionality with both.

Step 4

Add a new command line option named "-count" that prints the number of students in the database. Do not add any other text to the output other than the number of records (use System.out.println(...)). Otherwise the automarker will get confused.

Step 5

Extend the functionality of the -search option so that it will search for a student number if it receives a number as an argument. Extend the functionality of the -delete option so that it will search for a student name if it receives a string as an argument.

Step 6

Test your code thoroughly. Make sure that every command works when the database is empty, when it has a few records, and when it has 50 or more records. For example, in one test case you can insert 20 students, delete 10, search for 5 existing students, insert 20 more, delete 15, search for existing and non-existing students, and finally try to delete already-deleted students.

Files (also available in /h/u1/bureshop/pub):

Submission Instructions: Please submit all files needed to compile your code by 6pm on Tuesday, August 10. You can submit from within your CDF account by using submit -c csc263h -a prog4 {filenames}. You can get more information about submit in the man page.