Em Andamento

Train 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?

## Deliverables

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 [url removed, login to view];

class Main

{

public static void main(String[] args){

int passageTime, eastboundLimit, westboundLimit;

boolean lockTunnel = true;

if ([url removed, login to view] != 4) {

[url removed, login to view]("usage: passageTime numberEast numberWest lockTunnel");

[url removed, login to view](" passageTime is the length, in milliseconds, of the tunnel transition");

[url removed, login to view](" number(East, West) are the number of trains in each direction");

[url removed, login to view](" lockTunnel is a yes or no indicating whether to keep the tunnel from simultaneous access");

[url removed, login to view](" good values are 100 for passageTime, 10 for each limit and yes/no for lockTunnel");

[url removed, login to view](-1);

}

[url removed, login to view]("Collisions will be indicated");

[url removed, login to view]("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 {

[url removed, login to view](2000);

}

catch (InterruptedException e) {

[url removed, login to view](0);

}

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

// independently.

}

}

???? class Train ???

{

}

???? class Tunnel ????

{

}

## Platform

windows, java

Habilidades: Engenharia, Java, MySQL, PHP, Arquitetura de software, Teste de Software

Ver mais: true results, system.err.println java, system err println, system err, java system err, get length of string in c, finite it, err java, 2000 seconds, train, java thread, Finite, php detect system, create java object, java program synchronization, string integer, track object, random string, collision, hint system, train use, transition static, java detect, sleep variables php, random integer number

Acerca do Empregador:
( 11 comentários ) United States

ID do Projeto: #3021814

Premiar a:

coderden

See private message.

$2 USD em 3 dias
(119 Avaliações)
7.0

2 freelancers are bidding on average $4 for this job

puricelu

See private message.

$5.95 USD in 3 dias
(19 Comentários)
4.2