Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Comments

Спринт 2. Проектная работа No1.#1

Open
Main-expert wants to merge 4 commits intomain from
dev
Open

Спринт 2. Проектная работа No1. #1
Main-expert wants to merge 4 commits intomain from
dev

Conversation

@Main-expert
Copy link
Owner

@Main-expert Main-expert commented Dec 18, 2024

No description provided.

Comment on lines +2 to +3
public String nameCar; // Название автомобиля
public int speed; // Скорость автомобиля
Copy link

@ArturNurtdinov ArturNurtdinov Dec 18, 2024

Choose a reason for hiding this comment

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

Поля лучше пометить final, тем самым исключив возможность их модификации извне

System.out.println("Введите скорость машины No" + i + ":");
if (scanner.hasNextInt()) { // Проверяем, что введено число
speed = scanner.nextInt();
if (speed >= 0 && speed <= 250) {
Copy link

@ArturNurtdinov ArturNurtdinov Dec 18, 2024

Choose a reason for hiding this comment

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

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


// Выводим победителя
System.out.println("Самая быстрая машина: " + race.currentLeader);
scanner.close(); // Закрываем Scanner
Copy link

@ArturNurtdinov ArturNurtdinov Dec 18, 2024

Choose a reason for hiding this comment

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

Молодец, что не забыл вызвать close() у объекта Scanner, заботиться об очистке ресурсов - очень важный навык

Comment on lines +2 to +3
public String currentLeader = ""; // Текущий лидер
public int distanceLeader = 0; // Дистанция текущего лидера
Copy link

@ArturNurtdinov ArturNurtdinov Dec 18, 2024

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

Reviewers

1 more reviewer

@ArturNurtdinov ArturNurtdinov ArturNurtdinov left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /