-
Notifications
You must be signed in to change notification settings - Fork 0
Add new classes and it's first work version #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
src/main/java/MainMenu.java
Outdated
|
|
||
| // int peopleCount = scanner.nextInt(); | ||
| String peopleCountStr = scanner.next(); | ||
| if (peopleCountStr.matches("\\d*")){ |
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.
вместо регулярок можно использовать конструкцию try/catch вместе с функцией nextInt(). Код будет ожидать число и если это будет не оно, то код будет падать с ошибкой, которую ты будешь ловить в catch.
Либо же сканер может проверять ввод с помощью функции hasNextInt(), которая возвращает true, если ввод может быть приведен к числу
src/main/java/MainMenu.java
Outdated
| private void addProduct(){ | ||
|
|
||
| System.out.println("Введите название товара"); | ||
| String name = 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.
метод next() получает только первое слово, если вводить например "вода минеральная", используй вместо nextLine()
src/main/java/MainMenu.java
Outdated
| System.out.printf((message) + "%n", cheque, "рублей"); | ||
| } else if (cheque >= 1.00 && cheque < 2.00) { | ||
| System.out.printf((message) + "%n", cheque, "рубль"); | ||
| } else if (cheque >= 2.00 && cheque < 10.00) { |
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.
пять рубля, шесть семь восемь?
Изменена система проверки ввода из консоли. Убран общий метод addProduct, на его месте теперь два отдельных метода addProductName и addProductCost. В каждом методе теперь свой сканер, связанно это с тем, что общий сканер для всего класса MainMenu выдавал сбои. Fixed an error when displaying prices from 5 to 10 rubles. The system for checking input from the console has been changed. The general method addProduct has been separate into two methods addProductName and addProductCost, and removed. Each method now has its own scanner, because common scanner can makes errors.
…адежах слова "рубль" исправлена. Redesigned method showChequeAndProducts in the MainMenu class. The error in the cases of the word "ruble" has been corrected.
…адеже в зависимости от цены. Сделано это для более легкого чтения кода. A new method getRubCase has been added, which transmits the word "ruble" in the case depending on the price. This is done for easier code reading.
Первая версия.
При вводе числовых символов пользователем, дабы избежать ошибок, я использовал String.matches, что предполагает использование регулярных выражений, однако мы их не проходили. Отсюда вопрос, как в таком случае обойтись без регулярных выражений?