import java.util.Scanner; public class Main { public static void main(String[] args) { // ЧиÑаем авÑо Auto[] arrayAuto = requestCar(); // ÐпÑеделÑем Ñамого бÑÑÑÑого Auto fastest = Race.fastest(arrayAuto); // ÐÑводим System.out.println(String.format("Ð¡Ð°Ð¼Ð°Ñ Ð±ÑÑÑÑÐ°Ñ Ð¼Ð°Ñина: %s(%d)", fastest.name, fastest.speed)); } static Auto[] requestCar() { Scanner scanner = new Scanner(System.in); Auto[] arrayAuto = new Auto[3]; for (int i = 0; i <= 2; i++) { String name = ""; int speed = 0; String question = "ÐведиÑе Ð¸Ð¼Ñ Ð°Ð²Ñо:"; while (!Auto.nameVerf(name)) { System.out.println(question); name = scanner.next(); question = "ÐекоÑÑекÑное Ð¸Ð¼Ñ Ð°Ð²Ñо, повÑоÑиÑе:"; } question = "ÐведиÑе ÑкоÑоÑÑÑ Ð°Ð²Ñо (Ð¾Ñ 1 до 250, Ñелое):"; while (!Auto.speedVerf(speed)) { System.out.println(question); if (scanner.hasNextInt()) { speed = scanner.nextInt(); question = "ЧиÑло не в диапазоне(Ð¾Ñ 1 до 250), повÑоÑиÑе:"; } else { question = scanner.next() + " - ÑÑо не Ñелое ÑиÑло, повÑоÑиÑе:"; } } arrayAuto[i] = new Auto(name, speed); } return arrayAuto; } } class Race { static Auto fastest(Auto[] arrayAuto) { Auto fastest = arrayAuto[0]; int maxSpeed = 0; for (Auto auto : arrayAuto) { if (auto.speed > maxSpeed) { maxSpeed = auto.speed; // вмеÑÑо ÑкоÑоÑÑи можно поÑÑиÑаÑÑ ÑаÑÑÑоÑние, но заÑем? fastest = auto; } } return fastest; } } class Auto { String name; int speed; public Auto(String name, int speed) { this.name = name; this.speed = speed; } static boolean nameVerf(String name) { return !name.isEmpty(); // ÑÑда можно бÑÐ´ÐµÑ Ð´Ð¾Ð±Ð°Ð²Ð¸ÑÑ Ð¿ÑовеÑки Ð´Ð»Ñ Ð¸Ð¼ÐµÐ½Ð¸ } static boolean speedVerf(int speed) { return 0 < speed & speed <= 250; } }