this is on a class apart from other, the goal is that the passangers go from the airport to A and then to B and then back to the airport, but when the passangers want to go back to the airport from B, most times it appears that they arrived at the airport and then appears other message saying they are going back to the airport, what can i do? Can show other classes aswell
public void run() {
try {
Thread.sleep(new Random().nextInt(50)); //time till it gets to the airport
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("The " + currentThread().getName() + " started the trip with " + numPeople + " passangers!");
try {
Thread.sleep(new Random().nextInt(100)); //time till it gets to A
} catch (InterruptedException e) {
e.printStackTrace();
}
ms.addGuiaCondutor(this);
synchronized (obj) {
try {
obj.wait();
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
try {
Thread.sleep(100); //time till it gets to B
} catch (InterruptedException e) {
e.printStackTrace();
}
fd.addGuiaCondutor(this);
try {
Thread.sleep(500); //time till it gets to the airport
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("O " + currentThread().getName() + " arrived at the airport!");
ga.guiasCondutores.remove(this);
}
To better understand, this is the output i get, ignoring all other , look at the Driver1
Client 1 is in queue
Client 2 is in queue
Client 3 is in queue
Client 4 is in queue
Client 5 is in queue
Client 6 is in queue
Driver 1 was called to the airport driving: Bus
Driver 1 is in Queue to Museu Serralves!
Driver 1 is starting the visit to Museu Serralves!
Client 7 is in queue
Client 8 is in queue
Client 9 is in queue
Driver 2 was called to the airport driving: Taxi/Uber
Client 10 is in queue
Driver 2 is in Queue to Museu Serralves!
Client 11 is in queue
Client 12 is in queue
Driver 3 was called to the airport driving: Bus
Driver 3 is in Queue to Museu Serralves!
Driver 1 finished the visit to Museu Serralves!
Driver 1 is starting the trip to next destiny: Foz do Douro!
Driver 2 is starting the visit to Museu Serralves!
Driver 1 is in Queue to Foz do Douro!
Driver 1 is starting the visit to Foz do Douro!
Driver 1 arrived at the airport! !Here is the Problem!
Driver 2 finished visiting Museu Serralves!
Driver 2 is starting the trip to next destiny: Foz do Douro!
Driver 1 ended the visit to Foz do Douro! Driver 1 is on is way back to the Airport!
the problem is that driver 1 has to arrive at the airport after the last phrase on the output, not before i can show other classes