package racetrack;

public class Race {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Horse horse1 = new Horse("Dynamite");
		Horse horse2 = new Horse("Revenge");
		Horse horse3 = new Horse("Salutation");
		Horse horse4 = new Horse("Sloe Gin");

		double distance1 = 0;
		double distance2 = 0;
		double distance3 = 0;
		double distance4 = 0;

		while (distance1 < 1000 && distance2 < 1000 &&
               distance3 < 1000 && distance4 < 1000) {
			distance1 = horse1.run();
			distance2 = horse2.run();
			distance3 = horse3.run();
			distance4 = horse4.run();

			print(horse1);
			print(horse2);
			print(horse3);
			print(horse4);
			System.out.println();
			
			pause();
		}
		
		Horse winner = horse1;
		if (horse2.distance > winner.distance) {
			winner = horse2;
		}
		if (horse3.distance > winner.distance) {
			winner = horse3;
		}
		if (horse4.distance > winner.distance) {
			winner = horse4;
		}
		
		System.out.println("And the winner is " + winner.name + "!!!!!");
	}
	
	public static void print(Horse horse) {
		System.out.println("Horse " + horse.name +
				" has run " + horse.distance);
	}

	public static void pause() {
		try {
			Thread.sleep(300);
		}
		catch (InterruptedException e) {}
	}
}
