This homework is due before class on February 4.
There are two parts to this assignment: a paper design of a class hierarchy and an implementation of a program demonstrating basic object-oriented design.
1) [10 points] Design a class hierarchy, similar to the one designed in class, for something of interest to you. Your design need not be complex or elaborate, but it must be well thought out. A design with five to ten classes, three to five of which form a subclass chain, will suffice. Describe some possible methods and instance and class variables for all classes in the hierarchy. Pay particular attention to abstraction boundaries.
2) [40 points] Your task is to design and implement an object-oriented program to operate stop lights.
public boolean isOn()
public void toggle()
int or String
are obvious choices; document your design decision.
Write a class constructor to initialize the color upon object construction.
class StopLight {
}
Design and implement a subclass of StopLight for a unidirectional
stoplight (UniLight)
that can change from red to green to yellow and back to red.
Your design should include methods to change and retrieve the light's state:
public void change()
public state-type getState()
state-type depends
on your encoding of color bulbs from (b). The change() method
should change the light's state to the next color; i.e.,
from red to green
in the first call, then from green to yellow in the next call, etc.
public void change()
public state-type getState(dir-type dir)
state-type
again depends on your representation for color bulbs
and dir-type depends on the representation for directions.
if-then-else-if...
constructs. Instead, try to utilize arrays indexed by state counters.
Recall that an integer mod (%) N
can be used to keep such counters in range of an array of size N.
Hand in: a written description for (1), the complete code and
comments for (2), and a script of the output of (2e).
instructions on how to submit