Java Reference
In-Depth Information
super (name);
trafficLight # tLight;
inPhotoCell # inPhC;
outPhotoCell # outPhC;
stoppingBar # bar;
ticketDispenser # dispenser;
// attaches to the events raised by the physical devices
this .attachTo(tLight);
this .attachTo(dispenser);
this .attachTo(bar);
}
public void run() {
while (alive)
try {
switch (phase) {
case 1:
// waits for the traffic light
waitEvent(trafficLight, "GREEN");
// a new car proceeds to the ticket dispenser
thread.sleep(500);
goTo(20);
inPhotoCell.occupy();
goTo(170);
inPhotoCell.clear();
this .notifyObservers("PROCEEDING");
goTo(320);
phase # 2; break ;
case 2:
// waits for the ticket
waitEvent(ticketDispenser, "DELIVERED");
// withdraws the ticket
thread.sleep(1500);
ticketDispenser.withdraw();
phase # 3; break ;
case 3:
// waits for the stopping bar to be raised
waitEvent(stoppingBar, "UP");
// proceeds through the second photocell
goTo(470);
outPhotoCell.occupy();
goTo(650);
outPhotoCell.clear();
// enters the car park
goTo(750);
inside # false ;
distance # 0;
Search WWH ::




Custom Search