I have copied and pasted directly from the task conditions.
Also tried including a new line character but nothing I have tried works.
Example output: The winner is Boots!
package com.codegym.task.task21.task2113;
import java.util.List;
import java.util.ArrayList;
public class Hippodrome {
private List<Horse> horses;
static Hippodrome game;
public Hippodrome(List<Horse> horses) {
this.horses = horses;
}
public List<Horse> getHorses() {
return horses;
}
public static void main(String[] args) throws InterruptedException {
game = new Hippodrome(new ArrayList<Horse>());
Horse horse1 = new Horse("Lucky", 3, 0);
Horse horse2 = new Horse("Seabiscuit", 3, 0);
Horse horse3 = new Horse("Slevin", 3, 0);
game.getHorses().add(horse1);
game.getHorses().add(horse2);
game.getHorses().add(horse3);
game.run();
game.printWinner();
}
public void run() throws InterruptedException {
for (int i = 1; i <= 100; i++) {
move();
print();
Thread.sleep(200);
}
}
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 = null;
double distance = 0;
for (Horse horse : horses) {
if (horse.getDistance() > distance) {
winner = horse;
distance = horse.getDistance();
}
}
return winner;
}
public void printWinner() {
System.out.printf("The winner is %s!", getWinner().getName());
}
}