-
Notifications
You must be signed in to change notification settings - Fork 0
Comments
Conversation
# Conflicts: # src/main/java/goodsAddingEngine.java
...тывается некорректный ввод, прога вылетает
...le, переписал логику в новом классе goodsEntering, вылетов нет
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.
Можешь применить в студии автоформатирование (в выбранном файле, сверху вкладка Code - Reformat Code, либо Ctrl+Alt+L), тогда автоматически код выправится.
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.
Приведение типа к double (код (double) перед sum) необязательно, потому что sum и так типа double
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.
Double с большой буквы это класс-обертка, а здесь достаточно использовать примитив double. Подробнее про классы-обертки будет в спринте 3, тема 1, урок 2 Списки. ArrayList
Инициализация 0d здесь необязательно, поскольку до использования переменной её значение будет перезаписано enteredPrice = price.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.
Очень долго промучился с проверками и типами данных(( В результате душевной травмы пробовал принудительно присваивать типы некоторым значениям переменных))
Стало большим сюрпризом, что нужно очищать буфер сканера, иначе случался вылет в ошибку...
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.
Можно сделать цикл бесконечным while(true), а при проверках ввода ставить 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.
Сэкономил строчки кода на проверках и 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.
Можно вместо qtyOfGoods использовать goodsArray.size(). Это ещё и предотвратит от попытки получить элемент по индексу, который больше размера массива
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.
Можно метод делать не статическим, тогда для его вызова надо создавать экземпляр класса goodsEntering, и вызывать метод от экземпляра
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
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.
Достаточно здесь написать в скобках true, и необходимости в переменной flag не будет
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.
Можно более простые варианты: для определения последней цифры - payInputNorm % 10. Плюс учесть, что для чисел 11-19 окончание слова - "рублей", поможет payInputNorm % 100
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.
Классный подход, спасибо 👍)
Рабочий коммит - 050