-
Notifications
You must be signed in to change notification settings - Fork 0
First #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
First #1
Conversation
| /* логика установки скорости с валидацией введенных симоволов и рекурсивно заставляю ввести | ||
| верное значение с указанием какие значения от него ожидаются | ||
| */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
В целом по коду уже понятно что делает функция. Здесь не нужен комментарий.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Так же комментарии принято писать на английском, но это, конечно, не обязтательно.
| 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); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Логичнее было бы хранить num внутри самого класса Car как переменную и задавать в конструкторе.
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Переменная создаётся и не используется.
| 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); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try-catch довольно дорогая операция, правильнее было бы использовать hasNextInt()
No description provided.