-
Notifications
You must be signed in to change notification settings - Fork 0
Проектная работа №1 #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
- Добавлена проверка уникальности названий машин - Реализована валидация скорости - Оптимизирована структура классов ## Комментарии: Задание выполнено в полном соответствии с требованиями. Обратите внимание на новые проверки ввода.
| 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, тем самым исключив возможность их модификации извне, тогда можно убрать геттеры и поля сделать публичными
| while (true) { | ||
| System.out.println("Введите название машины №" + i + ":"); | ||
| name = scanner.nextLine().trim(); | ||
| if (!name.isEmpty()) { | ||
| break; | ||
| } | ||
| 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.
Код для считывания непустой строки с ввода лучше вынести в отдельную функцию - код, разделённый на небольшие функции, легче читать, поддерживать и переиспользовать
| System.out.println("Введите скорость машины №" + i + ":"); | ||
| 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.
Минимальную и максимальную скорости лучше вынести в константы для повышения читабельности кода
| private String leaderName; | ||
| private int leaderDistance; |
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, или нажать сочетание клавиш из соответствующего пункта в меню.
Сдача работы