import java.util.Scanner; public class Main { // ÐÑÐ½ÐµÑ ÑÑо возможно в конÑÑанÑÑ public static final int minSpeed = 0; public static final int maxSpeed = 250; public static final int racingTime = 24; public static void main(String[] args) { Scanner scanner = new Scanner(System.in); // ÐÑи ÑегиÑÑÑаÑии ÑÑаÑÑников ÑÑÐ°Ð·Ñ Ð²ÑÑиÑлÑем победиÑÐµÐ»Ñ Ð³Ð¾Ð½Ð¾Ðº Car leader = null; int maxDistance = 0; for (int i = 0; i < 3; i++) { int numberOfParticipant = i + 1; System.out.println("ÐведиÑе Ð¸Ð¼Ñ " + numberOfParticipant + " ÑÑаÑÑника"); String currentName; while ((currentName = scanner.nextLine()).trim().isEmpty()) { System.out.println("ÐÑ Ð²Ð²ÐµÐ»Ð¸ некоÑÑекÑное Ð¸Ð¼Ñ ÑÑаÑÑника!"); } int currentSpeed = inputSpeed(scanner, numberOfParticipant); scanner.nextLine(); Car currentCar = new Car(currentName, currentSpeed); int currentDistance = currentCar.getDistance(racingTime); if (leader == null) { leader = currentCar; maxDistance = currentDistance; } else { if (maxDistance < currentDistance) { leader = currentCar; maxDistance = currentDistance; } } } System.out.println("Ргонке победил авÑÐ¾Ð¼Ð¾Ð±Ð¸Ð»Ñ " + leader.name); scanner.close(); } // ÐÑÐ½ÐµÑ ÐºÐ¾Ð´ ввода ÑкоÑоÑÑи в оÑделÑнÑÑ ÑÑнкÑÐ¸Ñ public static int inputSpeed(Scanner scanner, int numberOfParticipant) { int currentSpeed = -1; System.out.println("ÐведиÑе ÑкоÑоÑÑÑ Ð°Ð²ÑÐ¾Ð¼Ð¾Ð±Ð¸Ð»Ñ " + numberOfParticipant + " ÑÑаÑÑника в диапазоне Ð¾Ñ " + minSpeed + " до " + maxSpeed + " км/Ñ"); while (true) { if (!scanner.hasNextInt()) { System.out.println("ÐÑ Ð²Ð²ÐµÐ»Ð¸ ÑÑо-Ñо не Ñо!"); // ÑÑо-Ñо без ÑÑого ÑÑ Ð¾Ð´Ð¸Ñ Ð² беÑконеÑнÑй Ñикл, навеÑное нÑжно ввод как-Ñо пÑоÑиÑаÑÑ scanner.nextLine(); } else { currentSpeed = scanner.nextInt(); if (currentSpeed <= minSpeed || currentSpeed >= maxSpeed) { System.out.println("ÐведиÑе знаÑение ÑкоÑоÑÑи в диапазоне Ð¾Ñ " + minSpeed + " до " + maxSpeed + " км/Ñ"); scanner.nextLine(); } else { break; } } } return currentSpeed; } }