-
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
mikelog
commented
Jul 31, 2025
- Добавлен класс Car
- Добавлен класс Race
- Реализовано консольное приложение.
| 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, тем самым исключив возможность их модификации извне
| while(carName.isEmpty()){ | ||
| System.out.println("Введите марку автомобиля №" + (i+1)); | ||
| carName = scanner.nextLine(); | ||
| if(carName.isEmpty()){ | ||
| System.out.println("Марка автомобиля не может быть пустой \n"); | ||
| } | ||
| } |
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("Марка автомобиля не может быть пустой \n"); | ||
| } | ||
| } | ||
| while(carSpeed<0 || carSpeed > 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.
Минимальную и максимальную скорости лучше вынести в константы для повышения читабельности кода
| public static void main(String[] args) { | ||
| System.out.println("Hello world!"); | ||
| Scanner scanner = new Scanner(System.in); | ||
| ArrayList<Car> cars = new ArrayList<>(); |
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.
От хранения массива машин и лишнего цикла при определении победителя можно избавиться, если при вводе данных сразу вычислять победителя и хранить его в отдельной переменной, тогда программа будет требовать меньше памяти и работать быстрее
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.
@ArturNurtdinov то есть просто создать 3 разных объекта? car1, car2, car3 и при создании дергать класс гонки, чтобы сетить лидера?
| String leader = ""; | ||
| int distance = 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.
Два поля можно пометить private, чтобы скрыть логику работы определения победителя от внешних классов