See More

import static java.lang.Integer.parseInt; import java.util.ArrayList; import java.util.Scanner; public class Main { public static Scanner scanner = new Scanner(System.in); public static void main(String[] args) { System.out.println("Добро пожаловать на 24 часа Ле-Мана!"); Race race; ArrayList racersList = new ArrayList<>(); String needAnotherRaceStr; boolean bNeedAnotherRace; while (true) { racersList.clear(); while (true) { System.out.println("Введите количество учавствующих в заезде автомобилей:"); String racersNum = scanner.next(); if (racersNum.matches("-?\\d+")) { if (parseInt(racersNum) > 0) { for (int i = 0; i < parseInt(racersNum); i++) { racersList.add(appendCar(i)); } break; } else { System.out.println("Некорректное число участников заезда"); } } else System.out.println("Некорректное число участников заезда"); } race = new Race(racersList); race.startRace(); race.getResult(); while (true) { System.out.println("Желаете провести еще один заезд? Да/Нет"); needAnotherRaceStr = scanner.next(); if (needAnotherRaceStr.equals("Да")) { bNeedAnotherRace = true; break; } else if (needAnotherRaceStr.equals("Нет")) { bNeedAnotherRace = false; break; } else System.out.println("Некорректный ввод"); } if (!bNeedAnotherRace) break; } } public static Car appendCar(int number) { String carName; String carSpeed; while (true) { System.out.println("Введите название автомобиля №" + (number + 1)); carName = scanner.next(); if (carName.isBlank()) { System.out.println("Некорректное название автомобиля"); } else break; } while (true) { System.out.println("Введите скорость автомобиля №" + (number + 1) + " в диапазоне от 0 до 250 км\\ч"); carSpeed = scanner.next(); if (carSpeed.matches("-?\\d+")) { if (parseInt(carSpeed) >= 0 && parseInt(carSpeed) <= 250) { break; } else System.out.println("Некорректная скорость"); } else System.out.println("Некорректная скорость"); } return new Car(parseInt(carSpeed), carName); } }