Single Lane Bridge

Cars cannot pass each other on the bridge. The buttons set the number of cars moving in each direction. The default is one blue car and one red car. Try two and three. The safe checkbox, if cleared, changes the bridge monitor to a null implementation. The fair checkbox, when ticked, changes the bridge monitor to one which guarantees fair access to both red and blue cars.

RedCar.java

BlueCar.java

Bridge.java

SafeBridge.java

FairBridge.java

BridgeCanvas.java

SingleLaneBridge.java