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

Практическая работа No1 в курсе Яндекс Практикума#1

Open
shishinmaks wants to merge 1 commit intomain from
dev
Open

Практическая работа No1 в курсе Яндекс Практикума #1
shishinmaks wants to merge 1 commit intomain from
dev

Conversation

@shishinmaks
Copy link
Owner

@shishinmaks shishinmaks commented Dec 4, 2025

No description provided.

Comment on lines +2 to +3
String name;
int speed;
Copy link

@ArturNurtdinov ArturNurtdinov Dec 4, 2025

Choose a reason for hiding this comment

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

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

Comment on lines +5 to +6
String name; // название машины
int speed; // скорость машины
Copy link

@ArturNurtdinov ArturNurtdinov Dec 4, 2025

Choose a reason for hiding this comment

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

Переменные лучше объявлять максимально близко к их первому месту использования для повышения читабельности кода

System.out.println("Hello world!");
String name; // название машины
int speed; // скорость машины
int countAuto = 3; // количество автомобилей, учавствующих в гонке
Copy link

@ArturNurtdinov ArturNurtdinov Dec 4, 2025

Choose a reason for hiding this comment

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

От этой переменной можно избавиться, если перенести это значение в константу - private static final int AUTO_COUNT = 3

Comment on lines +15 to +24
while(true){
System.out.println("- Введите название машины No " + i);
name = scanner.nextLine();
// если ввели пустое название, пропускаем эту итерацию для новой попытки
if (name.isEmpty()){
System.out.println("Название машины не может быть пустым.");
continue;
}
break; // выход из цикла, если ввели корректное название машины
}
Copy link

@ArturNurtdinov ArturNurtdinov Dec 4, 2025

Choose a reason for hiding this comment

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

Код для считывания непустой строки с ввода лучше вынести в отдельную функцию - код, разделённый на небольшие функции, легче читать, поддерживать и переиспользовать

continue;
}
// если ввели некорректное значение, пропускаем эту итерацию для новой попытки
if (speed <= 0 || speed > 250 ){
Copy link

@ArturNurtdinov ArturNurtdinov Dec 4, 2025

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 によって変換されたページ (->オリジナル) /