Hello guys
I'm trying to write a simple class RaceOfJumpingCars , i have all methods done, but one of them doesn't work as it should.
Method advanceAllCars (no arguments, no return value)should move all cars refrenced by racingCar1, racingCar2 and racingCar3, they only can move from position 1 by randomly generated numbers from 1 and 3 inclusive.and they should move one by one But when the first car reach position 15 it wins the race and the other cars stop moving and the method should does nothing
my approach is
public void advanceAllCars()
{
while(this.raceOver !=true)
{
if(this.getRacingCar1().getPosition()<=15)
{
this.advanceRacingCar(racingCar1);//using another method advanceRacing Car
}
if(this.getRacingCar2().getPosition()<=15)
{
this.advanceRacingCar(racingCar2);
}
if(this.getRacingCar3().getPosition()<=15)
{
this.advanceRacingCar(racingCar3);
}
}
}
But for example when one of the cars reaches the 15 position , other still moving,
please guys give me an advice what to change in my loop?
lucas

