Skip to content

Conversation

@AlexejIvanov
Copy link
Owner

Pull Reques для проектной работы №1

Comment on lines +2 to +3
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 +15 to +24
while (true) { //создаем бесконечный цикл

System.out.println("- Введите название машины №" + i);
name = scanner.nextLine();
if (name.isEmpty()) { // проверка на пустую строку
System.out.println("Название автомобиля не может быть пустым!");
} else {
break;
}
}

Choose a reason for hiding this comment

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

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

continue;
}
speed = Integer.parseInt(input);
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 +2 to +3
String raceLeader = ""; // автомобиль-лидер
int wayLeader = 0; // дистанция, которую прошел лидер

Choose a reason for hiding this comment

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

Эти переменные можно пометить 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