Подскажите, пожалуйста, что не так? Вроде, все работает...
package com.javarush.task.task21.task2113;
import java.util.*;
public class Hippodrome {
private List<Horse> horses;
public static Hippodrome game;
public List<Horse> getHorses() {
return horses;
}
public Hippodrome(List<Horse> horses) {
this.horses = horses;
}
public static void main(String[] args) {
List<Horse> horses = new ArrayList<>();
Horse belka = new Horse("Belka", 3, 0);
Horse strelka = new Horse("Strelka", 3, 0);
Horse chernysh = new Horse("Chernysh", 3, 0);
horses.add(belka);
horses.add(strelka);
horses.add(chernysh);
game = new Hippodrome(horses);
game.run();
game.printWinner();
}
public void run() {
for (int i = 0; i < 100; i++) {
move();
print();
try {
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public void move() {
for (Horse horse : horses) {
horse.move();
}
}
public void print() {
for (Horse horse : horses) {
horse.print();
}
for (int i = 0; i < 10; i++) {
System.out.println();
}
}
public Horse getWinner() {
Horse winner = horses.get(0);
for (int i = 0; i < horses.size()-1; i++) {
if (winner.getDistance() < horses.get(i+1).getDistance()) winner = horses.get(i+2);
}
return winner;
}
public void printWinner() {
System.out.println("Winner is " + getWinner().getName() + "!");
}
}