-
Notifications
You must be signed in to change notification settings - Fork 0
Проект "Гонка" #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/Car.java
Outdated
| private String name; | ||
| private 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, тем самым исключив возможность их модификации извне. Геттеры можно удалить и поля сделать публичными - тогда можно будет получать доступ к переменным напрямую, а не через геттеры
src/main/java/Main.java
Outdated
| Scanner scanner = new Scanner(System.in); | ||
| Race race = new Race(); | ||
|
|
||
| int carCount = 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.
Это можно вынести в константу на уровне класса:
private static final int MAX_CARS = 3;
src/main/java/Main.java
Outdated
| System.out.println("Введите скорость автомобиля " + i + " (от 1 до 250): "); | ||
| try { | ||
| speed = Integer.parseInt(scanner.nextLine()); | ||
| 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.
Минимальную и максимальную скорости лучше вынести в константы для повышения читабельности кода
src/main/java/Main.java
Outdated
| } | ||
| } | ||
|
|
||
| Car car = new Car(name, 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.
Здесь отступ чуть уехал, в IDE можно сделать авто форматирование, нажав ПКМ по нужному классу и выбрав Reformat code, или нажать сочетание клавиш из соответствующего пункта в меню.
src/main/java/Race.java
Outdated
| private int winnerDistance = 0; | ||
|
|
||
| public void checkWinner(Car car) { | ||
| int distance = car.getSpeed() * 24; |
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.
24 тоже стоит вынести в константу с говорящим названием для повышения читабельности кода
No description provided.