Skip to content

Проект "Гонка"#1

Open
Lahtinart wants to merge 2 commits into
mainfrom
dev
Open

Проект "Гонка"#1
Lahtinart wants to merge 2 commits into
mainfrom
dev

Conversation

@Lahtinart
Copy link
Copy Markdown
Owner

No description provided.

Comment thread src/main/java/Car.java Outdated
Comment on lines +2 to +3
private String name;
private 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 thread src/main/java/Main.java Outdated
Scanner scanner = new Scanner(System.in);
Race race = new Race();

int carCount = 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.

Это можно вынести в константу на уровне класса:
private static final int MAX_CARS = 3;

Comment thread src/main/java/Main.java Outdated
System.out.println("Введите скорость автомобиля " + i + " (от 1 до 250): ");
try {
speed = Integer.parseInt(scanner.nextLine());
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 Outdated
}
}

Car car = new Car(name, 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.

Здесь отступ чуть уехал, в IDE можно сделать авто форматирование, нажав ПКМ по нужному классу и выбрав Reformat code, или нажать сочетание клавиш из соответствующего пункта в меню.

Comment thread src/main/java/Race.java Outdated
private int winnerDistance = 0;

public void checkWinner(Car car) {
int distance = car.getSpeed() * 24;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

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