-
Notifications
You must be signed in to change notification settings - Fork 0
"Проектная работа №1": передаю на ревью. #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
ArturNurtdinov
left a comment
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/Car.java
Outdated
| public String getCarName() { | ||
| return carName; | ||
| } | ||
|
|
||
| // Метод для установки названия машины | ||
| public void setCarName(String carName) { | ||
| this.carName = carName; | ||
| } | ||
|
|
||
| // Метод для получения скорости машины | ||
| public int getRaceCar() { | ||
| return raceCar; | ||
| } | ||
|
|
||
| // Метод для установки скорости машины | ||
| public void setRaceCar(int raceCar) { | ||
| this.raceCar = raceCar; | ||
| } |
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
src/main/java/Car.java
Outdated
| String carName; | ||
| int raceCar; |
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, тем самым исключив возможность их модификации извне
| public Car() { | ||
| this.carName = ""; | ||
| this.raceCar = 0; | ||
| } |
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
| Scanner scanner = new Scanner(System.in); | ||
| Race race = new Race(); | ||
|
|
||
| Car[] cars = new Car[3]; |
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
| if (winners.size() == 1) { | ||
| System.out.println("Наш победитель - самая быстрая машина: " + winners.get(0)); | ||
| } else { | ||
| System.out.print("Победителей несколько - самые быстрые машины: "); |
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
| System.out.println("Введите скорость " + (i + 1) + " автомобиля (не больше 250 и не меньше 1)"); | ||
| try { | ||
| int speed = scanner.nextInt(); | ||
| if (speed > 0 && speed <= 250) { |
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.
Минимальную и максимальную скорости лучше вынести в константы для повышения читабельности кода
Прошу проверить проектную работу №1 (Гонки) на ревью.
Написано консольное приложение, которое задает вопросы с консоли, считывает пользовательский ввод и в результате выводит победителя гонки.
В приложении есть три класса: Main, Race, Car.
Класс Car — содержит в себе параметры «название» и «скорость».
Класс Race – в данном классе рассчитывается и запоминается лидер гонок.
Main – в данном классе происходит считывание пользовательского ввода и коммуникация с остальными классами.
Буду благодарна, если отметите все недочеты, которые есть.