-
Notifications
You must be signed in to change notification settings - Fork 222
Пишем консольное приложение #118
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: master
Are you sure you want to change the base?
Conversation
| if (Math.floor(price) >= 11 && Math.floor(price) <= 14) { | ||
| return roubleCase = " рублей"; | ||
| } else { | ||
| remainder = Math.floor(price) % 10; |
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.
Math.floor(price) считается 3 раза, можно посчитать 1 раз и записать в переменную
| @@ -0,0 +1,20 @@ | |||
| public class CaseEnding { | |||
|
|
|||
| static String roubleCase = " рублей"; | |||
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.
Переменную можно убрать, и ниже при возврате результата писать просто return " <нужное слово>";. Или оставить переменную, но убрать здесь инициализацию, в каждом if убрать return, оставить только присваивание переменной нужного слова, а после всех if-else поставить return roubleCase;
| static double remainder; | ||
|
|
||
| static String setEnding(double price) { | ||
| if (Math.floor(price) >= 11 && Math.floor(price) <= 14) { |
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.
Если здесь добавить деление по модулю на 100 Math.floor(price) % 100, то для 111, 211 и т.д. будет работать тоже
|
|
||
| public class Item { | ||
|
|
||
| static String name; |
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.
Все модификаторы static можно в этом классе убрать, а при вызове метода calculate в Main сначала создавать объект класса Item. Подробнее про static будет в следующих уроках, пока в нем сильной необходимости нет
| static String values = ""; | ||
| static double sum = 0; | ||
|
|
||
| static void calculate() { |
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.
Можно результатом этого метода возвращать посчитанную sum, тогда не надо будет её использовать в Main, код будет выглядеть логичнее
|
|
||
| while (true) { | ||
|
|
||
| printMenu(); |
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, тогда он будет печататься один раз, в принципе этого достаточно для пользователя
Добрый день! Задание по спринту 2.