Skip to content

Conversation

@SanguiniAvari
Copy link
Owner

No description provided.

Comment on lines +22 to +24
/* логика установки скорости с валидацией введенных симоволов и рекурсивно заставляю ввести
верное значение с указанием какие значения от него ожидаются
*/
Copy link

Choose a reason for hiding this comment

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

В целом по коду уже понятно что делает функция. Здесь не нужен комментарий.

Copy link

Choose a reason for hiding this comment

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

Так же комментарии принято писать на английском, но это, конечно, не обязтательно.

Comment on lines +26 to +41
Scanner scanner = new Scanner(System.in);
System.out.println("Введите скорость автомобиля №" + num + ":");
int curentSpeed;
try {
curentSpeed = scanner.nextInt();
if (curentSpeed > 0 && curentSpeed <=250){
speed=curentSpeed;
}else{
System.out.println("Введенное значение находится вне пределов от 1 до 250 включительно. Попробуйте снова.");
setSpeed(num);
}
} catch (InputMismatchException e){
System.out.println("Необходимо ввести число от 1 до 250 включительно.");
setSpeed(num);
}
}
Copy link

Choose a reason for hiding this comment

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

Логичнее было бы хранить num внутри самого класса Car как переменную и задавать в конструкторе.

Copy link

Choose a reason for hiding this comment

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

Так же логично было бы вынести всю логику по считыванию из класса Car и оставить тут только простой геттер.

}
//Вычисляем победителя
void whoWinn() {
Car car = new Car();
Copy link

Choose a reason for hiding this comment

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

Переменная создаётся и не используется.

Comment on lines +29 to +40
try {
curentSpeed = scanner.nextInt();
if (curentSpeed > 0 && curentSpeed <=250){
speed=curentSpeed;
}else{
System.out.println("Введенное значение находится вне пределов от 1 до 250 включительно. Попробуйте снова.");
setSpeed(num);
}
} catch (InputMismatchException e){
System.out.println("Необходимо ввести число от 1 до 250 включительно.");
setSpeed(num);
}
Copy link

Choose a reason for hiding this comment

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

try-catch довольно дорогая операция, правильнее было бы использовать hasNextInt()

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