Skip to content

Conversation

@Lyoncheese
Copy link
Owner

Первая версия.

public static double getDouble (Scanner scanner) {
try {
double num = scanner.nextDouble();
return num;

Choose a reason for hiding this comment

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

Можно просто return scanner.nextDouble();

if (rest1 >= 10 && rest1 <= 19) {
System.out.printf("%.2f Рублей", x);
}
else if (rest == 0 || rest >= 5 && rest <= 9) {

Choose a reason for hiding this comment

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

rest <= 9 - лишнее условие, rest >= 5 достаточно, так как при %10 и так будет 9 или меньше)

else if (rest == 1) {
System.out.printf("%.2f Рубль", x);
}
else if (rest >= 2 && rest <= 4) {

Choose a reason for hiding this comment

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

rest <= 4 также лишнее

} else {
System.out.println("Это некорректное значение для подсчёта");
}
}

Choose a reason for hiding this comment

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

Такие отдельные логические блоки, как этот (ввод и обработка количества людей), а также логические блоки с вводом товаров и выводом результатов лучше выносить в отдельные методы и затем вызывать их там, где необходимо. Это позволяет улучшить читаемость кода, т.к. разнородная логика не смешивается в один сплошной код, а также упрощает поддержку кода.

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