-
Notifications
You must be signed in to change notification settings - Fork 0
Приложение "Калькулятор Счёта" #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
src/main/java/Main.java
Outdated
| public static double getDouble (Scanner scanner) { | ||
| try { | ||
| double num = scanner.nextDouble(); | ||
| return 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.
Можно просто return scanner.nextDouble();
src/main/java/Main.java
Outdated
| if (rest1 >= 10 && rest1 <= 19) { | ||
| System.out.printf("%.2f Рублей", x); | ||
| } | ||
| else if (rest == 0 || rest >= 5 && rest <= 9) { |
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.
rest <= 9 - лишнее условие, rest >= 5 достаточно, так как при %10 и так будет 9 или меньше)
src/main/java/Main.java
Outdated
| else if (rest == 1) { | ||
| System.out.printf("%.2f Рубль", x); | ||
| } | ||
| else if (rest >= 2 && rest <= 4) { |
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.
rest <= 4 также лишнее
| } else { | ||
| System.out.println("Это некорректное значение для подсчёта"); | ||
| } | ||
| } |
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.
Такие отдельные логические блоки, как этот (ввод и обработка количества людей), а также логические блоки с вводом товаров и выводом результатов лучше выносить в отдельные методы и затем вызывать их там, где необходимо. Это позволяет улучшить читаемость кода, т.к. разнородная логика не смешивается в один сплошной код, а также упрощает поддержку кода.
Первая версия.