Homework 12
Version 1

 

Due by 8:00 AM on Monday, November 29, 1999
That is, on the Monday after Thanksgiving break.

Clarifications:

In the Course class, for "sorting itself by student id," read "finding a student by ID number." So the overall program should behave just like the program from assignment 11.

However, if you already added a "sort by ID number" behavior, this is also acceptable.

None of the classes (Course, Student, Database) should be sub-classes of another class. There should be three independent classes.

Here's one way to understand the division of responsibility between the classes. Suppose that I declared the data fields in Student private, so that methods from other classes could not get at them. The Student class should contain methods that let outsiders manipulate a Student object (e.g. ask if a student is below the ITR cutoff) by calling methods of the Student class rather than by directly accessing the data fields of the Student object. We don't make you actually declare these fields private, because you may have trouble doing this completely. But it's the idea you should aim for.

So the Student class contains methods that manipulate the data fields of a student. The Course class has methods that manipulate a whole array of students (and which typically call methods of the Student class to help them). The Database class contains the main method and the menu interface for interacting with the user.

There are several reasonable ways to choose a set of method for the Student or Course class. It is not necessary to exactly duplicate the set of methods I would have chosen. You just have to make a reasonable division of responsibility between the three classes.


The assignment is simply to rebuild your solution to the last assignment using objects with behavior. You should center the design on two classes:

  1. Student, which stores the information and behaviors for a single student. Its behaviors include: prompting the user to input values to fill in its fields, printing itself out on one line, responding (with a boolean value) whether it is in trouble or not (given some cutoff gpa), responding whether or not it is on the honor roll, etc.

    (Note that the method that causes the object to get values from the user for its fields should NOT be one of the constructor methods for the class. It is bad style to have user input or output occur in a constructor method.)

  2. Course, which is built around an array of Students. Its behaviors include adding new students to itself, sorting itself by student name, sorting itself by student id, printing honor rolls and ITR lists, etc. (Note, we could have called the class Class. Since java is case sensitive, this would not have interfered with the reserved-word status of the keyword class. However, we might as well avoid the postential confusion on your part.)

Note: As with Homework 12, you should include all three classes (Student, Course, and your driver class Database, that actually uses the other two classes and runs the menu system, etc.) in a single file (NewDatabase.java) submitted as the solution to problem 1.

I strongly recommend that you submit this program before break, so that you can relax over break. I'm giving you until the following Monday just case any of you need the additional flexibility in scheduling your work.

Last modified August 28 for Fall 99 cs5 by fleck@cs.hmc.edu


This page copyright ©1997 by Joshua S. Hodas. It was built with Frontier on a Macintosh . Last rebuilt on Sun, Dec 7, 1997 at 12:32:39 PM.
http://www.cs.hmc.edu/~hodas/courses/cs5/week_12/homework.html