Skip to content

Conversation

@Yarogi
Copy link
Owner

@Yarogi Yarogi commented Aug 30, 2023

Несколько опоздал со сдачей, прошу прощенье)

}

}
class Calculator{

Choose a reason for hiding this comment

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

🍏 В Java принято каждый класс описывать в отдельном файле

System.out.println("Введите стоимость");
if (scanner.hasNextFloat()){
cost = scanner.nextFloat();
}else{scanner.next();}

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("Введите стоимость");

Choose a reason for hiding this comment

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

🍏 Круто было бы подсказать пользователю, в каком формате ему нужно ввести стоимость. Например, [руб,коп]

Calculator calc = new Calculator(participantsQuantity);

String userDeсision = "";
String breakDeсision = "Завершить";

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 + "\")");

Choose a reason for hiding this comment

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

👏 Круто, что сообщаешь пользователю, как выйти из сценария

}

float result = this.cost / this.participantsQuantity;
System.out.println("Количество участников: " + this.participantsQuantity + " \nДобавленные товары: \n" + this.products + "\n-> Итого с человека: " + CurrencyFormatter.getCostRepresentation(result));

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(
//Поправил, сделал правда через формат.

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