Skip to content

Conversation

@Waitingshep
Copy link
Owner

Гоночки, тачки, скорость

Comment on lines +11 to +19
while (true) {
System.out.println("Введите название автомобиля №" + i + ": ");
name = scanner.nextLine().trim();
if (name.isEmpty()) {
System.out.println("Вы забыли ввести название автомобиля, попробуйте еще!");
continue;
}
break;
}

Choose a reason for hiding this comment

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

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

}

speed = Integer.parseInt(input);
if (speed > 0 && speed <= 250) {

Choose a reason for hiding this comment

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

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

System.out.println("Вы забыли ввести скорость, попробуйте еще!");
continue;
}
if (!input.matches("\\d+")) {

Choose a reason for hiding this comment

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

Проверка input.matches("\\d+") не гаранитрует, что ниже parseInt не выбросит исключение - лучше обработать исключение, чтобы была гарантия отсутствия ошибок

Comment on lines +51 to +52
String name;
int speed;

Choose a reason for hiding this comment

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

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

}
}

class Car {

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.

3 participants