Skip to content

Conversation

@Bjjyx
Copy link
Owner

@Bjjyx Bjjyx commented Aug 24, 2023

Первая версия.
При вводе числовых символов пользователем, дабы избежать ошибок, я использовал String.matches, что предполагает использование регулярных выражений, однако мы их не проходили. Отсюда вопрос, как в таком случае обойтись без регулярных выражений?


// int peopleCount = scanner.nextInt();
String peopleCountStr = scanner.next();
if (peopleCountStr.matches("\\d*")){

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, если ввод может быть приведен к числу

private void addProduct(){

System.out.println("Введите название товара");
String name = scanner.next();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

метод next() получает только первое слово, если вводить например "вода минеральная", используй вместо nextLine()

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) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

пять рубля, шесть семь восемь?

Bjjyx added 3 commits August 25, 2023 13:40
Изменена система проверки ввода из консоли.
Убран общий метод 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants