@@ -0,0 +1,1913 @@
+package com.javarush.task.task16.task1607;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0A/* %0AHorse Racing%0A*/%0A%0Apublic class Solution %7B%0A    public static int countHorses = 10;%0A%0A    public static void main(String%5B%5D args) throws InterruptedException %7B%0A        List%3CHorse%3E horses = prepareHorsesAndStart();%0A        while (calculateHorsesFinished(horses) != countHorses) %7B%0A        %7D%0A    %7D%0A%0A    public static int calculateHorsesFinished(List%3CHorse%3E horses) throws InterruptedException %7B%0A        int countFinished = 0;%0A        //add your implementation here - %D0%B4%D0%BE%D0%B1%D0%B0%D0%B2%D1%8C %D1%81%D0%B2%D0%BE%D1%8E %D1%80%D0%B5%D0%B0%D0%BB%D0%B7%D0%B0%D1%86%D0%B8%D1%8E %D1%82%D1%83%D1%82%0A        for (Horse horse : horses) %7B%0A            if (!horse.isFinished()) %7B%0A                System.out.println(%22Waiting for %22 + horse.getName());%0A                horse.join();%0A            %7D else %7B%0A                countFinished++;%0A            %7D%0A        %7D%0A        return countFinished;%0A    %7D%0A%0A    public static List%3CHorse%3E prepareHorsesAndStart() %7B%0A        List%3CHorse%3E horses = new ArrayList%3CHorse%3E(countHorses);%0A        String number;%0A        for (int i = 1; i %3C countHorses + 1; i++) %7B%0A            number = i %3C 10 ? (%220%22 + i) : %22%22 + i;%0A            horses.add(new Horse(%22Horse_%22 + number));%0A        %7D%0A%0A        for (int i = 0; i %3C countHorses; i++) %7B%0A            horses.get(i).start();%0A        %7D%0A        return horses;%0A    %7D%0A%0A    public static class Horse extends Thread %7B%0A%0A        private boolean isFinished;%0A%0A        public Horse(String name) %7B%0A            super(name);%0A        %7D%0A%0A        public boolean isFinished() %7B%0A            return isFinished;%0A        %7D%0A%0A        public void run() %7B%0A            String s = %22%22;%0A            for (int i = 0; i %3C 1001; i++) %7B   //delay%0A                s += %22%22 + i;%0A                if (i == 1000) %7B%0A                    s = %22 has finished the race!%22;%0A                    System.out.println(getName() + s);%0A                    isFinished = true;%0A                %7D%0A            %7D%0A        %7D%0A    %7D%0A%7D%0A

Complete task1607