Skip to content

Работа по калькулятору счета - #1

Open
Yarogi wants to merge 2 commits into
mainfrom
dev
Open

Yarogi wants to merge 2 commits into
mainfrom
dev

Conversation

@Yarogi

@Yarogi Yarogi commented Aug 30, 2023

Copy link
Copy Markdown
Owner

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

Comment thread src/main/java/Main.java Outdated
}

}
class Calculator{

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Comment thread src/main/java/Main.java Outdated
System.out.println("Введите стоимость");
if (scanner.hasNextFloat()){
cost = scanner.nextFloat();
}else{scanner.next();}

Copy link
Copy Markdown

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

Comment thread src/main/java/Main.java
String product = scanner.next();
float cost = 0f;
while (cost <= 0) {
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.

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

Comment thread src/main/java/Main.java Outdated
Calculator calc = new Calculator(participantsQuantity);

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

Copy link
Copy Markdown

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

Comment thread src/main/java/Main.java
}
calc.addProduct(product, cost);

System.out.println("Добавить ещё один товар? (Если это всё, введите \"" + breakDeсision + "\")");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Comment thread 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));

Copy link
Copy Markdown

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

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