Hello,
I couldn't manage to find the solution, so I snooped a bit in the help section. I stumbled upon this working code :
public static int calculateHorsesFinished(List<Horse> horses) throws InterruptedException {
int finishedCount = 0;
for (int i = 0;i< horses.size();i++){
if (horses.get(i).isFinished()){
finishedCount++;
}
else {
System.out.println("Waiting for " + horses.get(i).getName());
horses.get(i).join();
}
}
return finishedCount;
}
I thought my code was functionally identical, yet it doesn't work. Here it is :
public static int calculateHorsesFinished(List<Horse> horses) throws InterruptedException {
int finishedCount = 0;
for (int i = 0; i < horses.size(); i++) {
Horse horse = horses.get(i);
if(horse.isFinished){
finishedCount++;
} else{
System.out.println(String.format("Wait for %s", horse.getName()));
horse.join();
}
}
return finishedCount;
}
Can anyone explain the difference to me please ?