Skip to content

Приложение "Калькулятор Счёта" - #1

Open
Lyoncheese wants to merge 4 commits into
mainfrom
dev
Open

Lyoncheese wants to merge 4 commits into
mainfrom
dev

Conversation

@Lyoncheese

Copy link
Copy Markdown
Owner

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

Comment thread src/main/java/Main.java Outdated
public static double getDouble (Scanner scanner) {
try {
double num = scanner.nextDouble();
return num;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

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

Copy link
Copy Markdown

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 или меньше)

Comment thread src/main/java/Main.java Outdated
else if (rest == 1) {
System.out.printf("%.2f Рубль", x);
}
else if (rest >= 2 && rest <= 4) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

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

Copy link
Copy Markdown

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.

2 participants