public class Solution { public static void main(String[] args) throws InterruptedException { List<Horse> horses = prepareHorsesAndStart(10); while (calculateHorsesFinished(horses) != horses.size()) { } } public static int calculateHorsesFinished(List<Horse> horses) throws InterruptedException { int finishedCount = 0; //напишите тут ваш код int y = horses.size(); for (int i = 1; i < y; i++) { if ( horses.get(i).isFinished() == true ){ finishedCount ++; } else System.out.println( "Waiting for " + horses.get(i).getName()); horses.get(i).join(); // finishedCount ++; } // System.out.println("финишироало " + finishedCount + " лошадей"); return finishedCount; } public static List<Horse> prepareHorsesAndStart(int horseCount) { List<Horse> horses = new ArrayList<>(horseCount); String number; for (int i = 1; i < horseCount + 1; i++) { number = i < 10 ? ("0" + i) : "" + i; horses.add(new Horse("Horse_" + number)); } System.out.println("All horses start the race!"); for (int i = 0; i < horseCount; i++) { horses.get(i).start(); } return horses; } } class Horse extends Thread { private boolean isFinished; public Horse(String name) { super(name); } public boolean isFinished() { return isFinished; } public void run() { String s = ""; for (int i = 0; i < 1001; i++) { // Delay s += "" + i; if (i == 1000) { s = " has finished the race!"; System.out.println(getName() + s); isFinished = true; } } } }