Skip to content

add logic of Main, Car and Race classes - #1

Open
MaxDDM wants to merge 1 commit into
mainfrom
dev
Open

MaxDDM wants to merge 1 commit into
mainfrom
dev

Conversation

@MaxDDM

@MaxDDM MaxDDM commented Feb 11, 2026

Copy link
Copy Markdown
Owner

Сделана первая работа в соответствии с требованиями.

Comment thread src/main/java/Car.java
Comment on lines +2 to +3
String name;
short 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 thread src/main/java/Main.java
continue;
}

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 thread src/main/java/Main.java
}

break;
} while (true);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Не рекомендую писать бесконечные циклы через while (true) - лучше всегда явно прописывать условие выхода из цикла, чтобы уменьшить вероятность ошибиться и повысить читабельность кода

Comment thread src/main/java/Main.java
Comment on lines +55 to +57
Car car1 = createCar(1);
Car car2 = createCar(2);
Car car3 = createCar(3);

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 thread src/main/java/Race.java
@@ -0,0 +1,23 @@
public class Race {
Car car1, car2, car3;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

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