Skip to content

Практическая работа #1 - «24 часа Ле-Мана» - #1

Open
letav1n-i wants to merge 3 commits into
mainfrom
dev
Open

letav1n-i wants to merge 3 commits into
mainfrom
dev

Conversation

@letav1n-i

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

Copy link
Copy Markdown
Owner Author

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
Scanner scanner = new Scanner(System.in);
for (int i = 1; i < 4; i++) {

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

Copy link
Copy Markdown
Owner Author

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
Comment on lines +27 to +28
name = scanner.nextLine().trim();
if (name.isEmpty()) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Owner Author

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
}
}

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.

Код для считывания скорости с ввода аналогично лучше вынести в отдельную функцию

Copy link
Copy Markdown
Owner Author

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
showErrorInvalidCharacters();
} else {
speed = Integer.parseInt(inputSpeed);
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.

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

Copy link
Copy Markdown
Owner Author

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