Repository navigation
Conversation
Charmandik
reviewed
Aug 24, 2023
|
|
||
| // int peopleCount = scanner.nextInt(); | ||
| String peopleCountStr = scanner.next(); | ||
| if (peopleCountStr.matches("\\d*")){ |
There was a problem hiding this comment.
вместо регулярок можно использовать конструкцию try/catch вместе с функцией nextInt(). Код будет ожидать число и если это будет не оно, то код будет падать с ошибкой, которую ты будешь ловить в catch.
Либо же сканер может проверять ввод с помощью функции hasNextInt(), которая возвращает true, если ввод может быть приведен к числу
| private void addProduct(){ | ||
|
|
||
| System.out.println("Введите название товара"); | ||
| String name = scanner.next(); |
There was a problem hiding this comment.
метод next() получает только первое слово, если вводить например "вода минеральная", используй вместо nextLine()
Charmandik
reviewed
Aug 24, 2023
| 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) { |
Изменена система проверки ввода из консоли. Убран общий метод 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Первая версия.
При вводе числовых символов пользователем, дабы избежать ошибок, я использовал String.matches, что предполагает использование регулярных выражений, однако мы их не проходили. Отсюда вопрос, как в таком случае обойтись без регулярных выражений?