Assignment 1
CS 146
due September 18, 2002
100 points

Implement a simple student record system by defining three classes: StudentFile, StudentRecord, and CourseRecord. Test with the A1 class provided on the class web site.

A course record should represent the performance of a student in a course. It should contain at least information about the course prefix, the course number, the semester, the number of units, and the grade. You may assume that the course prefix and the grade are strings, and that the course number, the number of units, and the semester are integers.

The CourseRecord class should provide an constructor that takes these 5 components, in the order given above, as parameters. The number of units and the semester should be nonnegative and the course number should be positive, otherwise a NumberFormatException should be thrown. You may assume that the course prefix and the letter grade may be any legal string. You needn't worry about the interpretation of the semester integer. The CourseRecord class should also provide an equals method to help recognize duplicate records.

Instances of the StudentRecord class should contain information about the student identification number and the name of a single student. They should also contain the collection of all course records for the given student. The class should provide an constructor that takes an integer (representing the student id number) and a string (representing the student name). If the number is negative, the constructor should throw an exception. Otherwise, it should construct an instance of the class with the given number and name, an empty collection of course records.

The StudentRecord class should provide a method addCourse that adds a course record to the collection of course records. This method should take the same parameters as the CourseRecord constructor, in same order. If the constructor fails, or if a duplicate record is being added, the addCourse method should print an error message and not add the course record. The class should also provide a traverse method that prints the the student id # and name, followed by the information in each of the course records. The class should provide a computeGPA method that returns a value of type double that represents the student's overall GPA (for all of that student's classes), and a findGrade method that takes a course prefix and a course number, and returns a String representing the student's grade(s) for that course. If the course is taken more than once, then return the concatenation of the grade strings (ideally separated by spaces). Return the empty string if the course is not found. When computing GPA, give any string corresponding to the grades A, A-, B+, B, B-, C+, C, C-, D+, D, D-, or F, the numerical interpretation it receives at SJSU. Other strings should be interpreted as 0.

Instances of the StudentFile class should represent collections of student records. The constructor for this class should create an empty collection. The class should provide at least three additional public methods -- a addStudentRecord method that takes a StudentRecord object, and adds it to the collection, a getStudentRecord method that takes an id number and efficiently finds and returns the associated student record, and a traverse method that prints the id number, name, and GPA of every student in the file. The first method should return a boolean value with the same interpretation as in the add method of the Set classes. The second method should return null if no such record exists. It may, however, assume that every element in the collection is a student record.

You may define any other additional methods or classes you find helpful. However, you should not define any mutators, and you should not allow instance variables to be mutable through failure of encapsulation (e.g., don't make them public).

Note that this assignment will involve a considerable amount of work if you don't use the classes and methods provided in the Java API, but should not be too formidable if you do use these resources.