-
Notifications
You must be signed in to change notification settings - Fork 0
Консольное приложение JAVA. Яндекс.Практикум #1
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: main
Are you sure you want to change the base?
Conversation
SeveNChaK
left a comment
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.
В файлах код прыгает, отступы не одинаковые - рекомендую использовать встроенные форматтер. Если ты программируешь в IDE от JetBrains, то можешь пройтись по всем файлам и нажать комбинацию (Windows: Shift + Ctrl + Alt + L, MacOS: Shift + Option + Command + L), затем выбрать, какую часть кода хочешь изменить, и выполнить команду. Среда разработки автоматически сделает нужные отступы и переносы (как она это делает можно изменить в настройках, но дефолтные значения вполне нормальные).
src/main/java/Main.java
Outdated
| double totalAmount = 0.0; | ||
| while (true) { // не стал делать проверку по введенному значению. Она есть дальше при делении счета. | ||
| System.out.println("Введите название и цену товара! Если хотите закончить, то введите 'завершить'!"); | ||
| nameOfProduct = 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.
nextLine, чтобы считать всю строку, потому что если ввести название из нескольких слов, то приложение упадет, так как после прочтения первого слова пойдет читать цену товара
| System.out.println(String.format(fullListsCost, totalAmount) + calc.GetRubleAddition(priceOfProduct)); | ||
| break; | ||
| } else { | ||
| priceOfProduct = scanner.nextDouble(); |
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.
src/main/java/Main.java
Outdated
| while (true) { | ||
| while (!scanner.hasNextInt()) { | ||
| System.out.println("Не является числом, повторите ввод!"); | ||
| String numberOfPersons1 = 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.
Можно просто scanner.next(); без записи в переменную
src/main/java/Main.java
Outdated
| System.out.println("Не является числом, повторите ввод!"); | ||
| String numberOfPersons1 = scanner.next(); | ||
| } | ||
| while (scanner.hasNextInt()) { |
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.
Этот цикл не нужен, мы уже сделали проверку в предыдущем цикле, так что тут точно будет int
src/main/java/Main.java
Outdated
| numberOfPersons = scanner.nextInt(); | ||
| if (numberOfPersons <= 1) { | ||
| System.out.println("Количество персон должно быть больше 1. Повторите ввод!"); | ||
| } else if (numberOfPersons > 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.
Можно просто } else {
src/main/java/Calculator.java
Outdated
| @@ -0,0 +1,28 @@ | |||
| public class Calculator { | |||
| public String GetRubleAddition(double num) { | |||
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.
Методы принято называть с маленькой буквы
src/main/java/Main.java
Outdated
| System.out.println("Введите название и цену товара! Если хотите закончить, то введите 'завершить'!"); | ||
| nameOfProduct = scanner.next(); | ||
| Calculator calc = new Calculator(); | ||
| { |
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.
Похоже на лишнюю скобочку. Ты получается просто весь код еще дополнительно в блок обернул, в этом нет необходимости. Кажется, что можно убрать ее и соответствующую ей закрывающую скобку
Написал первое консольное приложение в Java. Для сдачи ПР в Яндекс.Практикум