-
Notifications
You must be signed in to change notification settings - Fork 0
Проектная работа №1 #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: master
Are you sure you want to change the base?
Conversation
| public class Car { | ||
| String name; | ||
| int speed; | ||
|
|
||
| void setCarName(String name) { | ||
| this.name = name; | ||
| } | ||
|
|
||
| void setSpeed(int speed) { | ||
| this.speed = speed; | ||
| } | ||
|
|
||
| String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| double calcKmForDay() { | ||
| return speed * 24; | ||
| } |
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.
Здорово, что вынес отдельно в класс логику.
| } else { | ||
| throw new Exception(); | ||
| } |
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 лучше использовать только когда что-то действительно идёт не так. В данном случае лучше использовать if/else/
| } catch (InputMismatchException e) { | ||
| System.out.println("Ошибка: это не число"); | ||
| scan.next(); | ||
| } catch (Exception e) { | ||
| System.out.println("Ошибка: введите корректное число от 0 до 250"); | ||
| } |
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.
Здорово, что обрабатываешь ошибки, но здесь можно было сделать проще использую метод сканнера hasNextInt()
No description provided.