À quelle heure le train arrive-t-il ?
--One of the four phrases I remember from my month listening to "Learn French in your Car" tapes.
The goal of this lab is to practice using concurrency.
You will be working with a train simulation. There are two trains running on elliptical tracks that meet at four points. In the code as you get it, they will (almost certainly) crash at the crossings. You need to modify the code so that they do not crash.
Make a new directory for this lab and copy the files that I am giving you.
cp -r ~tvandrun/Public/cs245/lab11/trains .
Use a text editor (gedit or xemacs or whatever you prefer)
to open the files Train.java
,
Track.java
, and TrackPosition.java
.
(For several of the classes I've provided
only the compied version.
Eclipse doesn't like that.)
Try running the program as it is and confirm that the
trains crash.
The class with the main method is trains.Trains
.
java trains.Trains
Then fix it.
All the coding you need to do is in Train.java
.
All you need to know about the rest of the code you
can learn by looking at the interfaces Track.java
and TrackPosition.java
.
The only new thing you need to know about Java is
how locks, monitors, and synchronized stuff works.
Trains take up six track positions at a time---but since they are moving, it's often a good idea to give them a little space.
Don't forget to recompile Train.java
.
If you're used to working in Eclipse, this is an easy thing to forget.