import java.util.Scanner; public class Main { public static final int MIN_SPEED = 0; public static final int MAX_SPEED = 250; public static Scanner scanner = new Scanner(System.in); public static void main(String[] args) { Race race = new Race(); for (int i = 0; i < 3; i++) { race.checkLider(newCar()); } race.printLiderName(); scanner.close(); } public static Car newCar() { while (true) { System.out.println("ÐведиÑе название авÑомобилÑ: "); String name = scanner.next(); if (!isNameCorrect(name)) { continue; } System.out.println("ÐведиÑе ÑкоÑоÑÑÑ Ð°Ð²ÑомобилÑ: "); String speed = scanner.next(); if (!isSpeedCorrect(speed)) { continue; } return new Car(name, Integer.parseInt(speed)); } } private static boolean isSpeedCorrect(String speed) { if (speed.isBlank()) { System.out.println("ÐÑибка. СкоÑоÑÑÑ Ð°Ð²ÑÐ¾Ð¼Ð¾Ð±Ð¸Ð»Ñ Ð½Ðµ должна бÑÑÑ Ð¿ÑÑÑой. ÐведиÑе даннÑе еÑе Ñаз."); return false; } for (int i = 0; i < speed.length(); i++) { if (!Character.isDigit(speed.charAt(i))) { System.out.println("ÐÑибка. СкоÑоÑÑÑ Ð°Ð²ÑÐ¾Ð¼Ð¾Ð±Ð¸Ð»Ñ Ð´Ð¾Ð»Ð¶Ð½Ð° ÑодеÑжаÑÑ ÑолÑко ÑиÑÑÑ. ÐведиÑе даннÑе еÑе Ñаз."); return false; } } int speedInt = Integer.parseInt(speed); if (speedInt < MIN_SPEED || speedInt > MAX_SPEED) { System.out.println("ÐÑибка. СкоÑоÑÑÑ Ð°Ð²ÑÐ¾Ð¼Ð¾Ð±Ð¸Ð»Ñ Ð´Ð¾Ð»Ð¶Ð½Ð° бÑÑÑ Ð² диапазоне Ð¾Ñ 0 до 250. ÐведиÑе даннÑе еÑе Ñаз."); return false; } return true; } private static boolean isNameCorrect(String name) { if (!name.isBlank()) { System.out.println("ÐÑибка. Ðазвание авÑÐ¾Ð¼Ð¾Ð±Ð¸Ð»Ñ Ð½Ðµ должно бÑÑÑ Ð¿ÑÑÑÑм. ÐведиÑе даннÑе еÑе Ñаз."); return false; } return true; } }