Skip to content

Проектная работа 1 - #129

Closed
KonOsipov wants to merge 6 commits into
Yandex-Practicum:masterfrom
KonOsipov:master
Closed

KonOsipov wants to merge 6 commits into
Yandex-Practicum:masterfrom
KonOsipov:master

Conversation

@KonOsipov

Copy link
Copy Markdown

Проектная работа 1

Comment thread src/main/java/Main.java Outdated
String stopInput;//завершение ввода

String foodName;//название товара
float foodPrice=0f;//цена товара

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
System.out.println("Калькулятор приветствует вас! Введите количество друзей!");

while(true)
{

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 принято открывающие фигурные скобки ставить на той же строке, без переноса:
while (true) {

Также есть полезный хоткей, который рекомендую использовать каждый раз после написания куска кода. Он форматирует код, приводя его к единому красивому стилю. Обычно это Ctrl + Alt+ L (jetbrains.com/help/idea/reformat-and-rearrange-code.html#reformat_code)

Copy link
Copy Markdown
Author

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/Calculator.java Outdated

public void AddTovarPrice(float foodPrice)//добавить цену на товар
{
totalPrice=totalPrice+foodPrice;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Можно использовать конструкцию totalPrice += foodPrice;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Да, но мне кажется totalPrice=totalPrice+foodPrice; более наглядно, хотя возможно дело привычки.

Comment thread src/main/java/Calculator.java Outdated

public void totalOutput(int numberOfFriends)//вывод результата
{
String formattedTotalPrice=String.format("%.2f", totalPrice);// приводим общую сумму к нужному виду

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Переменная formattedTotalPrice объявляется, но нигде не используется

Comment thread src/main/java/Calculator.java Outdated

System.out.println(tovarName+"\n"); //выводим список всех товаров

System.out.println("Общая сумма к оплате: "+String.format("%.2f", totalPrice));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Такие идущие подряд println лучше объединять в один

Copy link
Copy Markdown
Author

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/Calculator.java Outdated
}
else
{
System.out.println("Каждый друг должен "+ String.format("%.2f",(totalPrice/numberOfFriends))+" рубль!"+"\n");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Есть принцип, который называется DRY - Don't repeat yourself. По этому принципу, если есть многократные одинаковые фрагменты кода, то их лучше вынести отдельно. Здесь, например, можно отдельно вынести System.out.println("Каждый друг должен "+ String.format("%.2f",(totalPrice/numberOfFriends)) и к нему в зависимости от суммы добавлять "рубль", "рубля" или "рублей"

Copy link
Copy Markdown
Author

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