-
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
| } | ||
|
|
||
| } | ||
| class Calculator{ |
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.
🍏 В Java принято каждый класс описывать в отдельном файле
src/main/java/Main.java
Outdated
| System.out.println("Введите стоимость"); | ||
| if (scanner.hasNextFloat()){ | ||
| cost = scanner.nextFloat(); | ||
| }else{scanner.next();} |
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.
🍏 Немного поехало форматирование. Для форматирования кода и удаления неиспользуемых импортов применяй следующие сочетания клавиш:
Windows: Control+Alt+L
MacOS: Command+Option+L
Больше горячих клавиш можно найти здесь: https://developer.android.com/studio/intro/keyboard-shortcuts
| String product = scanner.next(); | ||
| float cost = 0f; | ||
| while (cost <= 0) { | ||
| 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.
🍏 Круто было бы подсказать пользователю, в каком формате ему нужно ввести стоимость. Например, [руб,коп]
src/main/java/Main.java
Outdated
| Calculator calc = new Calculator(participantsQuantity); | ||
|
|
||
| String userDeсision = ""; | ||
| String breakDeсision = "Завершить"; |
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.
🍏 Так как эта строка не меняется во время работы программы, можно вынести ее в константы. https://www.baeldung.com/java-constants-good-practices
| } | ||
| calc.addProduct(product, cost); | ||
|
|
||
| System.out.println("Добавить ещё один товар? (Если это всё, введите \"" + breakDeсision + "\")"); |
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.
👏 Круто, что сообщаешь пользователю, как выйти из сценария
src/main/java/Main.java
Outdated
| } | ||
|
|
||
| float result = this.cost / this.participantsQuantity; | ||
| System.out.println("Количество участников: " + this.participantsQuantity + " \nДобавленные товары: \n" + this.products + "\n-> Итого с человека: " + CurrencyFormatter.getCostRepresentation(result)); |
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.
🍏 При печати в памяти будут создаваться промежуточные строки из-за использования оператора "+". Можно использовать StringBuilder, который сформирует только результирующую строку. https://habr.com/ru/articles/260767/
|
|
||
| float result = this.cost / this.participantsQuantity; | ||
| 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.
👏 Тоже хорошее решение!
Несколько опоздал со сдачей, прошу прощенье)