-
Notifications
You must be signed in to change notification settings - Fork 0
Branch1 #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?
Branch1 #1
Conversation
src/main/java/Main.java
Outdated
| int AmountOfPeople = scan.nextInt(); | ||
| String AllNames = ""; | ||
| double AllPrices = 0; |
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.
🍏 Рекомендую имена переменным присваивать в соответствии со стилем lowerCamelCase
https://ru.wikipedia.org/wiki/CamelCase
Например, amountOfPeople.
А также не рекомендую использовать здесь scan.nextInt(); Лучше изначально присвоить 0 или ничего не присваивать. Об этом ниже
src/main/java/Main.java
Outdated
| while (AmountOfPeople == 1 || AmountOfPeople < 1) { | ||
| System.out.println("Введеное значение некоректно."); | ||
| AmountOfPeople = scan.nextInt(); | ||
| } |
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.
⚠ Здесь тебе необходимо добавить дополнительную обработку некорректного ввода. Т.е. при nextInt, в консоли ожидается цифра, но пользователь может ввести строку и программа "упадет" с ошибкой.
Используй в этом цикле scan.hasNextInt(). Для while можно задать условие true, а внутри проверять в первую очередь в if-else hasNextInt().
В случае, если введено не число, то выводим сообщение в консоль (тут важно еще вызвать scan.nextLine() ) и цикл продолжит работу до тех пор, пока не удовлетворяется условие hasNextInt().
В случае, если введено число, то дополнительно проверяешь: AmountOfPeople == 1 || AmountOfPeople < 1. Если больше одного, то break. Если нет, то выводим сообщение в консоль и цикл продолжит работу до тех пор, пока не удовлетворяется условие hasNextInt() и AmountOfPeople == 1 || AmountOfPeople < 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.
Я не очень понимаю, как сделать так чтобы пользователь мог ввести и число и строку. У меня есть переменная AmountOfPeople которая int. И не очень понятно как сделать так, чтобы пользователь мог ввести и то, и другое
src/main/java/Main.java
Outdated
| AllNames += name + " "; | ||
|
|
||
| System.out.println("Напишите цену товара:"); | ||
| double price = scan.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
| if (answer.equals("Завершить")) { | ||
| break; | ||
| } |
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.
🍏 Используй equalsIgnoreCase вместо equals. equalsIgnoreCase сравнивает строки без учета регистра букв. Т.е. можно написать зАвершить и equalsIgnoreCase вернет true
src/main/java/Main.java
Outdated
| System.out.println("Итоговая сумма с каждого гостя: " + result + " " + Format.Formarter(total)); | ||
| } | ||
|
|
||
| public static class Format { |
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.
⚠ Пусть этот класс будет объявлен за пределами класса Main. Сейчас получается, что он вложен в Main. Лучше исправить.
| } | ||
|
|
||
| public static class Format { | ||
| public static String Formarter(double x) { |
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.
🍏 Названия функций также лучше именовать с маленькой буквы по стилю lowerCamelCase. Также лучше давать более конкретные и соответствующие имена для аргументов функций
src/main/java/Main.java
Outdated
| if (x % 10 == 1) { | ||
| return "рубль"; | ||
| } else if (x % 10 == 2 || x % 10 == 3 || x % 10 == 4) { | ||
| return "рубля"; | ||
| } else { | ||
| return "рублей"; | ||
| } |
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.
⚠ Нужно дополнительно учесть, что для чисел 11-19 - должно быть "рублей" - для этого стоит проверять, что остаток от "<число> % 100" находится между 11 и 19 включительно. В прошлых итерациях эта проверка у тебя была (PR в репе Яндекса), поэтому трудностей у тебя не возникнет
Также рекомендую проверяемое число округлить и привести к int
int num = (int) Math.floor(x);
No description provided.