Java Reference
In-Depth Information
waitEvent(stoppingBar, "UP");
phase # 6; break ;
case 6:
// waits for the car to cross the second photocell
waitEvent(outPhotoCell, "OCCUPIED");
phase # 7; break ;
case 7:
// the car has crossed the second photocell
waitEvent(outPhotoCell, "CLEARED");
// the car has cleared the second photocell;
// lowers the stopping bar
stoppingBar.lower();
phase # 8; break ;
case 8:
// the controller waits for the stopping bar to be
// down
waitEvent(stoppingBar, "DOWN");
// set the trafficLight to green
trafficLight.setGreen();
phase # 1; break ;
}
}
}
Class Car animates the car moving along the access lane. Method run()
implements the finite state machine depicted in Figure 11.6.
package parking;
public class Car extends EventProcess {
TrafficLight trafficLight;
// a reference to the traffic light
PhotoCell inPhotoCell;
// a reference to the first photocell
PhotoCell outPhotoCell;
// a reference to the second photocell
StoppingBar stoppingBar;
// a reference to the stopping bar
TicketDispenser ticketDispenser;
// a reference to the ticket dispenser
int phase # 1;
// the counter of the current phase
int distance # 0;
// the position along the access lane
// the constructor
public Car(String name, TrafficLight tLight,
PhotoCell inPhC, PhotoCell outPhC,StoppingBar
bar, TicketDispenser dispenser) {
Search WWH ::




Custom Search