-
Notifications
You must be signed in to change notification settings - Fork 0
Dev #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
src/main/java/Main.java
Outdated
| System.out.println("Введите скорость машины " + nameCar+" :"); | ||
| int speedCar = scanner.nextInt(); | ||
| Car car = new Car(nameCar, speedCar); | ||
| if(car.speed>0&&car.speed<251){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Лучше вынести в константы минимальную и максимальную скорость
src/main/java/Main.java
Outdated
| while(true){ | ||
| System.out.println("Введите скорость машины "+ nameCar3); | ||
| int speedCar3 = scanner.nextInt(); | ||
| Car car3 = new Car(nameCar3, speedCar3); | ||
| if(car3.speed>0&&car3.speed<251){ | ||
| cars.add(car3); | ||
| System.out.println(car3.name + " подходит! Она проедет "+ leMan(car3.speed) +" км за 24 часа."); | ||
| break; | ||
| }else{ | ||
| System.out.println("Машина не подходит на гонку допускаются машины со скоростью до 250 км/ч. Попробуйте еще раз, так как скорость "+ car3.name +" = "+ car3.speed +" км/ч."); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Этот кусок кода повторяется три раза, его можно вынести в отдельную функцию
src/main/java/Main.java
Outdated
| String name; | ||
| int speed; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Эти переменные лучше пометить final
| if(cars.get(0).speed>cars.get(1).speed&&cars.get(0).speed>cars.get(2).speed){ | ||
| System.out.println("Самая быстрая машина: " + cars.get(0).name); | ||
| }else if(cars.get(1).speed>cars.get(0).speed&&cars.get(1).speed>cars.get(2).speed){ | ||
| System.out.println("Самая быстрая машина: " + cars.get(1).name); | ||
| }else if(cars.get(2).speed>cars.get(0).speed&&cars.get(2).speed>cars.get(1).speed){ | ||
| System.out.println("Самая быстрая машина: " + cars.get(2).name); | ||
| }else if(cars.get(0).speed==cars.get(1).speed&&cars.get(0).speed>cars.get(2).speed){ | ||
| System.out.println("Самые быстрые машины: " + cars.get(0).name+", "+cars.get(1).name); | ||
| }else if(cars.get(1).speed==cars.get(2).speed&&cars.get(1).speed>cars.get(0).speed) { | ||
| System.out.println("Самые быстрые машины: " + cars.get(1).name + ", " + cars.get(2).name); | ||
| }else if(cars.get(0).speed==cars.get(2).speed&&cars.get(1).speed>cars.get(1).speed) { | ||
| System.out.println("Самые быстрые машины: " + cars.get(0).name + ", " + cars.get(2).name); | ||
| } else{ | ||
| System.out.println("Все машины финишируют одинаково"); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Это бы тоже вынести в отдельную функцию и можно написать проще, т.к. такой многоэтажный if очень тяжело читать и понимать. В списке хранится скорость каждой из машин, которую можно умножить на 24 и вывести индекс того элемента списка, у которого получившееся значение выше остальных
| while(!prov2){ | ||
| System.out.println("Введите скорость машины " + nameCar3+" :"); | ||
| try{ | ||
| while(true){ | ||
| speedCar3 = scanner.nextInt(); | ||
| Car car3 = new Car(nameCar3, speedCar3); | ||
| if(car3.speed>0&&car3.speed<251){ | ||
| cars.add(car3); | ||
| System.out.println(car3.name + " подходит! Она проедет "+ leMan(car3.speed) +" за 24 часа."); | ||
| break; | ||
| }else{ | ||
| System.out.println("Машина не подходит на гонку допускаются машины со скоростью до 250 км/ч. Попробуйте еще раз, так как скорость "+ car3.name +" = "+ car3.speed +" км/ч."); | ||
| } | ||
| } | ||
| prov2 = true; | ||
| }catch(Exception exception){ | ||
| System.out.println("Некорректный ввод. Пожалуйста, введите скорость."); | ||
| scanner.nextLine(); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Общий код лучше выносить в отдельные функции. Сейчас у тебя копируется код, который считывает и валидирует каждую из машин, этот код можно обобщить в одной функции и использовать её в трёх местах
Разбираюсь, но вроде получилось