|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectedu.colorado.simulations.TrafficLight
public class TrafficLight
A TrafficLight object simulates a simple traffic light.
| Constructor Summary | |
|---|---|
TrafficLight(int r,
int g)
Construct a TrafficLight with a specified lengths of time
that the light stays red and green. |
|
| Method Summary | |
|---|---|
boolean |
isGreen()
Check whether this TrafficLight is green. |
boolean |
isRed()
Check whether this TrafficLight is red. |
void |
simulateTime(int t)
Simulate the passage of a certain amount of time for this TrafficLight. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public TrafficLight(int r,
int g)
TrafficLight with a specified lengths of time
that the light stays red and green.
r - the number of seconds that this light stays redg - the number of seconds that this light stays green
TrafficLight has been initialized. It starts
red and stays red for r seconds; then it switches to green for
g seconds, back to red for r seconds, back to green for g
seconds, and so on.
java.lang.IllegalArgumentException - Indicates that one of the parameters is zero or negative.| Method Detail |
|---|
public void simulateTime(int t)
TrafficLight.
t - the number of seconds to simulate during the call to this method
t >= 0.
TrafficLight has simulated the passage of
t more seconds of time.
java.lang.IllegalArgumentException - Indicates that t is negative.public boolean isRed()
TrafficLight is red.
- - none
TrafficLight is red, then the return
value is true; otherwise the return value is false.public boolean isGreen()
TrafficLight is green.
- - none
TrafficLight is green, then the return
value is true; otherwise the return value is false.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||