-
Notifications
You must be signed in to change notification settings - Fork 0
Домашнее задание 2го спринта #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?
Conversation
| public class Car { | ||
| String carName; | ||
| int carSpeed; | ||
| Car (String carName, int carSpeed) { | ||
| this.carName = carName; | ||
| this.carSpeed = carSpeed; | ||
| } | ||
| } |
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.
В Джаве принято делать поля приватными и писать для них геттеры и сеттеры.
| System.out.println("Введите скорость машины первого участника (это должно быть число больше 0 и меньше или равно 250):"); | ||
| String inputCarSpeed = userInput.nextLine(); | ||
| int carSpeed = inputCarSpeedToInt(inputCarSpeed); | ||
| Car firstCar = new Car(carName, carSpeed); | ||
| Race race = new Race(); | ||
| race.whoIsWinner(firstCar); | ||
| System.out.println("Введите название машины второго участника:"); | ||
| carName = userInput.nextLine(); | ||
| System.out.println("Введите скорость машины второго участника (это должно быть число больше 0 и меньше или равно 250):"); | ||
| inputCarSpeed = userInput.nextLine(); | ||
| carSpeed = inputCarSpeedToInt(inputCarSpeed); | ||
| Car secondCar = new Car(carName, carSpeed); | ||
| race.whoIsWinner(secondCar); | ||
| System.out.println("Введите название машины третьего участника:"); | ||
| carName = userInput.nextLine(); | ||
| System.out.println("Введите скорость машины третьего участника (это должно быть число больше 0 и меньше или равно 250):"); | ||
| inputCarSpeed = userInput.nextLine(); |
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.
Правильнее было бы сделать это в цикле
| } catch (NumberFormatException e) { | ||
| System.out.println("Неверно введена скорость! Введите число больше 0 и меньше или равной 250!"); | ||
| Scanner userInputSpeed = new Scanner(System.in); | ||
| inputSpeed = userInputSpeed.nextLine(); | ||
| } | ||
| } |
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.
Молодец, что сразу отловил исключение!
Домашнее задание от Артура Сафиуллина проект гонка Ле Ман.
Студент курса по Android-разработке. Когорта №27