Repository navigation
Conversation
|
Не знаю можно ли предыдущие комиты удалить да и нужно ли |
|
| } | ||
| } | ||
|
|
||
| class Calculation { |
There was a problem hiding this comment.
🍏 В Java принято каждый класс располагать в отдельном файле
|
|
||
| Calculation calculation = new Calculation(numberPersons); | ||
|
|
||
| System.out.println("Введите название товара и его стоимость"); |
There was a problem hiding this comment.
🍏 Классно было бы подсказать пользователю, в каком формате от него ожидаются данные. Например, [название руб.коп]. А также предложить способ выхода из сценария
| public class Main { | ||
| public static void main(String[] args) { | ||
| System.out.println("Hello world!"); | ||
| public void main(String[] args) { |
There was a problem hiding this comment.
| public void main(String[] args) { | |
| public static void main(String[] args) { |
| } else { | ||
| while (true) { | ||
| if (scanner.hasNextDouble()) { | ||
| double amount = scanner.nextDouble(); |
There was a problem hiding this comment.
🍏
| double amount = scanner.nextDouble(); | |
| double price = scanner.nextDouble(); |
|
|
||
| System.out.println("На сколько человек необходимо разделить счёт?"); | ||
|
|
||
| Scanner scanner = new Scanner(System.in); |
There was a problem hiding this comment.
🍏 Немного поехало форматирование. Для форматирования кода и удаления неиспользуемых импортов применяй следующие сочетания клавиш:
Windows: Control+Alt+L
MacOS: Command+Option+L
Больше горячих клавиш можно найти здесь: https://developer.android.com/studio/intro/keyboard-shortcuts
| while (true) { | ||
| if (scanner.hasNextDouble()) { | ||
| double amount = scanner.nextDouble(); | ||
| if (amount > 1) { |
There was a problem hiding this comment.
|
|
||
| System.out.println("Введите название товара и его стоимость"); | ||
|
|
||
| while (true) { |
There was a problem hiding this comment.
🍏 Рекомендую разделять большие методы на методы поменьше. Например, можно вынести этот цикл в отдельный метод
|
|
||
| class Calculation { | ||
|
|
||
| String productList = "Добавленные товары:"; |
There was a problem hiding this comment.
🍏 Можно сохранять товары в список и производить объединение в строку для печати в самом конце. Это дает больше гибкости в использовании данных, полученных от пользователя. Также не будет создаваться множество промежуточных строк, если для формирования финальной строки использовать StringBuilder множественной конкатенации с помощью +.
https://habr.com/ru/articles/260767/
| break; | ||
| } | ||
|
|
||
| return String.format("%.2f", result) + ending; |
There was a problem hiding this comment.
🍏
| return String.format("%.2f", result) + ending; | |
| return String.format("%.2f %s", result, ending); |
| } | ||
|
|
||
| public void addProduct(String product, double price) { | ||
| productList = productList + "\n" + String.format("%s стоимость: %.2f %s", product, price, getEnding(price)); |
There was a problem hiding this comment.
🍏
| productList = productList + "\n" + String.format("%s стоимость: %.2f %s", product, price, getEnding(price)); | |
| productList = String.format("%s\n%s стоимость: %.2f %s", productList, product, price, getEnding(price)); |
| System.out.println("Введите стоимость товара (руб,коп)."); | ||
| try { | ||
| double price = scanner.nextDouble(); | ||
| if (price > 1) { |
There was a problem hiding this comment.
No description provided.