Skip to content

Conversation

@segn1s
Copy link
Owner

@segn1s segn1s commented Mar 17, 2025

No description provided.

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, тем самым исключив возможность их модификации извне. Таким образом, геттеры можно будет удалить и получать значения полей по прямому доступу к ним

int speed = scanner.nextInt();
scanner.nextLine(); // Очистка буфера

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.

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

public class Race {
String currentLeaderName = "Лидер отсутствует";
int currentLeaderDistance = 0;
ArrayList<Auto> cars = new ArrayList<>();

Choose a reason for hiding this comment

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

От хранения массива машин и лишнего цикла при определении победителя можно избавиться, если при вводе данных сразу вычислять победителя и хранить его в отдельной переменной, тогда программа будет требовать меньше памяти и работать быстрее

Comment on lines +4 to +5
String currentLeaderName = "Лидер отсутствует";
int currentLeaderDistance = 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