Skip to content

Выполнение проектной работы №1#1

Open
AlexejIvanov wants to merge 1 commit intomainfrom
dev
Open

Выполнение проектной работы №1#1
AlexejIvanov wants to merge 1 commit intomainfrom
dev

Conversation

@AlexejIvanov
Copy link
Copy Markdown
Owner

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

Comment on lines +2 to +3
String name; // Название автомобиля
int speed; // Скорость автомобиля
Copy link
Copy Markdown

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;
}
}
Copy link
Copy Markdown

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) {
Copy link
Copy Markdown

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; // дистанция, которую прошел лидер
Copy link
Copy Markdown

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.

2 participants