Skip to content

Conversation

@Kdly9
Copy link
Owner

@Kdly9 Kdly9 commented Jul 29, 2024

No description provided.

Comment on lines +1 to +19
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;
}
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 +22 to +24
} else {
throw new Exception();
}
Copy link

Choose a reason for hiding this comment

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

try/catch лучше использовать только когда что-то действительно идёт не так. В данном случае лучше использовать if/else/

Comment on lines +25 to +30
} catch (InputMismatchException e) {
System.out.println("Ошибка: это не число");
scan.next();
} catch (Exception e) {
System.out.println("Ошибка: введите корректное число от 0 до 250");
}
Copy link

Choose a reason for hiding this comment

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

Здорово, что обрабатываешь ошибки, но здесь можно было сделать проще использую метод сканнера 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