Image

Help me!!

Here's the deal. I took an incomplete in advanced Java last quarter because I'd had a medical problem that set me back and was going to get a D. Since then, I've switched majors to hardware. Networking and probably repair. I'm doing A quality work in my first netowrking class but haven't had time to work on the last Java program I need to get done to bring that D up to a C. I'll get to retake the final in two weeks, so I've got to bone up on that as well.

The trouble is, I have this last lab and am confused about how it needs to be designed.


Name: Lab 7
Description: Trains Emulation
Model a two train system in which two Trains each approach a single Tunnel along a single track from opposite directions. The tunnel is single track which can only be used by one train at a time. Hint: the tunnel keeps track of which train is in the tunnel through an instance variable or variables Each train is under its own control. The program should provide a means to protect against collision within the tunnel which can be turned on and off during different invocations. How would you turn on and off synchronization of an object?

The program should detect collisions
Hint: a collision should be an inconsistent state, where the train which the tunnel thinks is in the tunnel after a transition is complete is not the train which entered the tunnel.

Each train takes a finite amount of time to use the tunnel and approach it. Hint: use times above 100ms for each transition to get good results. Each train should wait a random amount of time before attempting to use it


import java.util.Random;

class Main
{
public static void main(String[] args){
int passageTime, eastboundLimit, westboundLimit;
boolean lockTunnel = true;
if (args.length != 4) {
System.err.println("usage: passageTime numberEast numberWest lockTunnel");
System.err.println(" passageTime is the length, in milliseconds, of the tunnel transition");
System.err.println(" number(East, West) are the number of trains in each direction");
System.err.println(" lockTunnel is a yes or no indicating whether to keep the tunnel from simultaneous access");
System.err.println(" good values are 100 for passageTime, 10 for each limit and yes/no for lockTunnel");
System.exit(-1);
}

System.out.println("Collisions will be indicated");
System.out.println("Trains roll in 2 seconds\n\n");

passageTime = new Integer(args[0]).intValue();
eastboundLimit = new Integer(args[1]).intValue();
westboundLimit = new Integer(args[2]).intValue();
if (args[3].toLowerCase().equals("no")) {
lockTunnel = false;
}

try {
Thread.sleep(2000);
}
catch (InterruptedException e) {
System.exit(0);
}

// Create a Tunnel and two trains. The trains must run
// independently.
}
}

???? class Train ???
{

}



???? class Tunnel ????
{

}



Here's my question. Do I have the tunnel watch the trains or the trains watch the tunnel? Or is this something completely different? I can't save the objects to disk. They all have to live in thread format. If I could save the objects to disk it would be much easier to figure out.