Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Comments

Консольное приложение#1

Open
pakhomn wants to merge 3 commits intomain from
dev
Open

Консольное приложение #1
pakhomn wants to merge 3 commits intomain from
dev

Conversation

@pakhomn
Copy link
Owner

@pakhomn pakhomn commented Jun 30, 2023

Консольное приложение

}


System.out.println("Сумма на каждого: " + payment + " " + rub + "\n****");
Copy link

@faritowich faritowich Jun 30, 2023

Choose a reason for hiding this comment

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

Такие отдельные логические блоки, как этот (обработка окончаний), а также логические блоки с с вводом людей, вводом товаров и выводом результатов лучше выносить в отдельные сущности (методы и классы) и затем вызывать их там, где необходимо. Это позволяет улучшить читаемость кода, т.к. разнородная логика не смешивается в один сплошной код, а также упрощает поддержку кода.

на скольких человек необходимо разделить счёт.
*/

int k;
Copy link

@faritowich faritowich Jun 30, 2023

Choose a reason for hiding this comment

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

Лучше делать наименования более содержательными, эта тема хорошо раскрывается во 2 главе книги Роберта Мартина "Чистый код". Также на хабре есть краткий конспект книги: https://habr.com/ru/post/485118/

pr = scanner.nextDouble();
while (pr < 0) {
System.out.println("!! Цена должна быть положительным числом. Укажите новую цену.");
pr = 0.0;
Copy link

@faritowich faritowich Jun 30, 2023

Choose a reason for hiding this comment

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

pr = 0.0 - лишнее. В следующей строчке переприсваиваем

pr = 0.0;
pr = scanner.nextDouble();
}
sum = sum + pr;
Copy link

@faritowich faritowich Jun 30, 2023

Choose a reason for hiding this comment

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

Есть короткая конструкция sum += pr;

} else {
System.out.println("!! Укажите цену цифрами, для разделения используй запятую.\nНазвание товара укажи заново.\n");
}
Sku sku = new Sku(text, pr);
Copy link

@faritowich faritowich Jun 30, 2023

Choose a reason for hiding this comment

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

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



System.out.println("\n****\nСписок всех товаров:" + list.substring(0, list.length()) + "\n");
System.out.println("Общая сумма: " + sum + " Количество человек: " + k + "\n");
Copy link

@faritowich faritowich Jun 30, 2023

Choose a reason for hiding this comment

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

Такие подряд идущие println можно объединить в один.

Sku sku = new Sku(text, pr);
}

if (list.equals("")) {
Copy link

@faritowich faritowich Jun 30, 2023

Choose a reason for hiding this comment

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

Можно заменить на list.isEmpty

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer

@faritowich faritowich faritowich left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /