-
Notifications
You must be signed in to change notification settings - Fork 222
Проект готов 1. Спринт 2. #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
src/main/java/Main.java
Outdated
| } else { | ||
| System.out.println("Ошибка. Введите число."); | ||
| scanner.next(); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Лучше выносить большие блоки в отдельные методы или классы. Например, для обработки ввода количества людей создать метод void calcuLatePersons (или даже вынести логику в отдельный класс), в котором будет цикл и вся логика обработки ввода. то же касается метода по обработке ввода товаров и их стоимости. Это позволяет делать код более читабельным и аккуратным.
Вообще на тему того, как лучше организовать написание кода, могу посоветовать книгу Роберта Мартина "Чистый Код" .
src/main/java/Main.java
Outdated
| while (true) { | ||
| if (scanner.hasNextInt()) { | ||
| numberOfPeople = scanner.nextInt(); | ||
| if (numberOfPeople > 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Лучше по возможности избегать большой вложенности if'ов, это затрудняет понимание логики программы. Впрочем, иногда бывают случаи, когда с вложенными ифами лучше, чем без них
src/main/java/Main.java
Outdated
| calculator.setProducts(product); | ||
| calculator.setTotalPrice(price); | ||
| System.out.println("Товар успешно добавлен."); | ||
| System.out.println("Добавить ещё один товар?"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Чтобы не писать лишний код можно объединять два println в один
| @@ -0,0 +1,78 @@ | |||
| import java.util.Scanner; | |||
|
|
|||
| public class Assistant { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
В таком маленьком проекте это не столь принципиально, но в целом лучше давать сущностям более говорящие названия - чтобы сразу было понятно, для чего они нужны
Версия 1. "Консольное приложение"