Skip to content

Conversation

@sermakov
Copy link

@sermakov sermakov commented Nov 5, 2022

Добрый день! Задание по спринту 2.

if (Math.floor(price) >= 11 && Math.floor(price) <= 14) {
return roubleCase = " рублей";
} else {
remainder = Math.floor(price) % 10;

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 = " рублей";

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

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;
Copy link

@MagicUnderHood MagicUnderHood Nov 6, 2022

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

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();

Choose a reason for hiding this comment

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

Можно этот вывод вынести до while, тогда он будет печататься один раз, в принципе этого достаточно для пользователя

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.

2 participants