Cosc 215 - Program #4

A Student Database

Due: 3/27/08
Points: 50

A small college needs a database to keep track of its students. Each student is represented by a student record which contains the following information:

The first and last names are strings, the student ID number is a 5 digit number, the major is a string, and the GPA is a real number. You may assume that no two students have the same first and last names, and that each student has a unique student ID number. The database will keep track of students by either the first name + last name pair, or the student ID number. A user should be able to retrieve a student record by giving the first name + last name, or by giving the student ID number. A user may find (and print out) a student record, add a new student record, change the major or GPA of a student record, delete a student record, and list all of the student records in order by (last name, first name) or by the student ID number.

Your program should have a class StudentDB which implements the following methods:

void add(lastName, firstName, id, major, GPA)
Adds a new student record to the database.
StudentRecord find(lastName, firstName)
Returns the unique student record with the given first and last name, if one exists. Otherwise returns null.
StudentRecord find(id)
Returns the unique student record with the given student id number, if one exists. Otherwise returns null.
void delete(lastName, firstName)
Deletes the unique student record with the given first and last name, if one exists. Otherwise prints out an error message.
void delete(id)
Deletes the unique student record with the given student id number, if one exists. Otherwise prints out an error message.
void changeMajor(id, newMajor)
Changes the major of the student record with the given student id number to newMajor
void changeGPA(id, newGPA)
Changes the major of the student record with the given student id number to newGPA.
void listByName()
Prints out all the student records in order by (last name, first name).
void listByID()
Prints out all the student records in order by student id number.

In addition to implementing these operations, your program should include a main method that tests all of them in a reasonable fashion. The program should not read command from the user.

The program must implement and use in a meaningful way the Simple Database ADT. The implementation must be efficient, i.e., you should use a binary search tree for this assignment. You may use any code for the book, the notes, or from class, as long as you properly credit the code. You may not use an API for the binary search tree for this assignment.


If you have questions or comments, email me at simon@mathcs.duq.edu