Homework 3
CS202, Summer 2004
Due: Thursday, July 15
Please email your solutions to csun@calstatela.edu,
and make sure to use CS202 Summer 04
HW3 as the subject of the email. The email should include your
name, and the .java files for all the exercises as attachments.
For all homework assignments and projects, failing to comply with the required
code conventions (see Review of
Language Basics, slide #7) will incur a
credit penalty up to 10% of the total credit for the assignment.
1. Read the following sections of SUN's Java Tutorial
2.(60pt) [Stanford] For this problem, you will design and
implement Java classes suitable for storing information about
university instructors. There are three types of instructor: Professor,
Lecturer, and Grad student. At any time, an instructor
can best be described by three quantities: number of unread e-mail
messages, age, and number of eccentricities. An
instructor should respond to an init message which sets their
age and sets them to have no unread mail and no eccentricities.
There are two measures of an instructor's current mood: stress
and respect. An instructor's stress level is the number of
unread messages.
However, stress is never more than 1000. Grad students are the
exception. Their stress is double the number of unread messages and
their maximum stress is 2000. Generally, an instructor's level of
respect in the community is their age minus the number of
eccentricities. Respect can never be negative. Professors are the
exception: a Professor's eccentricities are regarded as "signs of a
troubled genius" thereby increasing respect. So for Professors respect
is age plus number of eccentricities.
Everything in an instructor's life is driven by receiving e-mail.
Several things happen when an instructor gets new, unread e-mail:
- First, the amount of unread mail is increased.
- Second, 90% of the time, there will be no change in the
eccentricities. 10% of the time, the number of eccentricities will
randomly go up or down by one.
- Third, the new unread mail may cause the instructor's stress
factor to become larger than their respect factor which makes the
instructor unhappy. In this case, instructors have different coping
mechanisms. Professors react by gaining 10 eccentricities. Lecturers
react by accidentally deleting half their unread mail. Grad students
react by reading all of their unread mail. The resulting mental anguish
causes the Grad student's eccentricities to go up or down by one
randomly. The coping mechanism may or may not bring the stress and
respect factors back in line. The coping mechanism is activated at most
one time for each batch of incoming mail.
To receive full credit for this exercise, you must take advantage of
inheritance to maximize code re-use, and it goes without saying that
you need some testing code, e.g. InstructorTest.java, to make sure your
classes and methods work properly.