Skip to content

Conversation

@Dila627
Copy link
Owner

@Dila627 Dila627 commented Sep 29, 2025

No description provided.

Comment on lines 13 to 21
while (name.isEmpty()) {

System.out.println("Введите название машины №:" + i + ":");
name = scanner.nextLine().trim();

if (name.isEmpty()) {
System.out.println("Название не может быть пустым");
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Код для считывания непустой строки с ввода лучше вынести в отдельную функцию - код, разделённый на небольшие функции, легче читать, поддерживать и переиспользовать


speed = scanner.nextInt();

if (speed >= 0 && speed <= 250) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Минимальную и максимальную скорости лучше вынести в константы для повышения читабельности кода

Comment on lines 57 to 58
String name;
int speed;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Поля лучше пометить final, тем самым исключив возможность их модификации извне

Comment on lines 69 to 70
String leadRacer = "";
int leadGap = 0;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Эти две переменные лучше сделать приватными, т.к. они относятся к внутренней логике работы этого класса. Для получения победителя гонки лучше написать отдельную функцию-геттер

- Имя машины через отдельный метод
- Проверка скорости через константы
- Поля Car final, поля Race private, добавлен геттер
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants