-
Notifications
You must be signed in to change notification settings - Fork 0
Create Race Game - first homework #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: dev
Are you sure you want to change the base?
Conversation
src/main/java/Main.java
Outdated
| while (name.isEmpty()) { | ||
|
|
||
| System.out.println("Введите название машины №:" + i + ":"); | ||
| name = scanner.nextLine().trim(); | ||
|
|
||
| if (name.isEmpty()) { | ||
| 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.
Код для считывания непустой строки с ввода лучше вынести в отдельную функцию - код, разделённый на небольшие функции, легче читать, поддерживать и переиспользовать
src/main/java/Main.java
Outdated
|
|
||
| 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.
Минимальную и максимальную скорости лучше вынести в константы для повышения читабельности кода
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, тем самым исключив возможность их модификации извне
src/main/java/Main.java
Outdated
| String leadRacer = ""; | ||
| int leadGap = 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.
Эти две переменные лучше сделать приватными, т.к. они относятся к внутренней логике работы этого класса. Для получения победителя гонки лучше написать отдельную функцию-геттер
- Имя машины через отдельный метод - Проверка скорости через константы - Поля Car final, поля Race private, добавлен геттер
No description provided.