Homework 3
CS202, Summer 2006
Due: Tuesday, July 25
Please upload your source code files using CSNS. Note
that file
uploading will be disabled automatically after 11:59PM
of the due date, so please turn in your work on time.
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. a InstructorTest.java program, to make sure your
classes and methods work properly.