Java Reference
In-Depth Information
Chapter 12 Self Test
the constants and their ordinal values.
4
.
The traffic light simulation developed in
Try This 12-1
can be improved with a few
simple changes that take advantage of an enumeration's class features. In the version
shown, the duration of each color was controlled by the
TrafficLightSimulator
class
by hard-coding these values into the
run( )
method. Change this so that the duration
of each color is stored by the constants in the
TrafficLightColor
enumeration. To do
this, you will need to add a constructor, a private instance variable, and a method
called
getDelay( )
. After making these changes, what improvements do you see? On
your own, can you think of other improvements? (Hint: Try using ordinal values to
switch light colors rather than relying on a
switch
statement.)
static members of all classes into view?
11
. What is a marker annotation?