Hi JPF. I'm having trouble with a question given to us by our lecturer. The question is as follows
In a toy train circuit (figure of eight) trains can enter via section 5 or section 14, do a figure of eight circuit and then leave via the same section that they entered.
A train joining the circuit must first make sure the section ahead and the section immediately to the right/left of them is free (e.g. A train entering via section 14 must ensure the section 14 and section 13, are not occupied by another train at that time. To avoid train crashes only one train at any time can be in any of the available sections. The crossover protocol at the junction (i.e. section 0) in the centre of the figure of eight is that the first train to get access to the junction is allowed to proceed across it.
The code that I have so far is below
public class traintrack { /*declare and initialise global variables */ final int NUMBER_OF_TRAINS= 20; int numberOnTrack = 0; //slots on the roundabout String sectionsOnTrack [] = {"[.....]", "[.....]", "[.....]", "[.....]","[.....]","[.....]","[.....]","[.....]","[.....]", "[.....]","[.....]","[.....]","[.....]","[.....]","[.....]","[.....]","[.....]","[.....]"}; } for (int count = 1; NUMBER_OF_TRAINS < 18; count++); { int entry = 5 & 14; int exit = 5 & 14; trainProcess (entry, exit); } //end for loop } //end main process Process trainProcess (int s, int t); { <await> (numberOnTrack <= 18, numberOnTrack++)>; //wait if track too crowded <await(sectionsOnTrack[2..s]=="[.....]"); AND (sectionsOnTrack[2..s+7])> } }
the reason it cuts off around the await section is because I am rather a beginner in using java and despite being a final year student have managed to get along doing modules that are not heavily focused on coding; but also I couldn't find much on java await statements by googling.
Any advice/nudges in the right direction would be appreciated.
Thanks