Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Comments

Pull request к приложению «Калькулятор счёта»#102

Open
Ilya-97 wants to merge 2 commits intoYandex-Practicum:master from
Ilya-97:master
Open

Pull request к приложению «Калькулятор счёта» #102
Ilya-97 wants to merge 2 commits intoYandex-Practicum:master from
Ilya-97:master

Conversation

@Ilya-97
Copy link

@Ilya-97 Ilya-97 commented Oct 29, 2022

Добавил обработку на вопрос про количество человек и стоимость с помощью методов scanner.hasNextInt() и hasNextFloat()

//Вывод суммы, которую должен заплатить каждый поровну
if ((money % 100) / 10 == 1){
System.out.println("Сумма, которую должен заплатить каждый человек составляет: " + str + " рублей");
}else if (money % 100 == 1){
Copy link

@MagicUnderHood MagicUnderHood Oct 29, 2022

Choose a reason for hiding this comment

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

Здесь лучше прописать money % 10 == 1, чтобы попадало 21, 51 и т.д.

System.out.println("Сумма, которую должен заплатить каждый человек составляет: " + str + " рублей");
}else if (money % 100 == 1){
System.out.println("Сумма, которую должен заплатить каждый человек составляет: " + str + " рубль");
}else if (money % 10 >= 2 && money % 10 <= 4){
Copy link

@MagicUnderHood MagicUnderHood Oct 29, 2022

Choose a reason for hiding this comment

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

Выражение money % 10 считается несколько раз, можно посчитать его один раз, записать в переменную и использовать ее

}else if (money % 10 >= 2 && money % 10 <= 4){
System.out.println("Сумма, которую должен заплатить каждый человек составляет: " + str + " рубля");
}else {
System.out.println("Сумма, которую должен заплатить каждый человек составляет: " + str + " рублей");
Copy link

@MagicUnderHood MagicUnderHood Oct 29, 2022

Choose a reason for hiding this comment

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

Код System.out.println("Сумма, которую должен заплатить каждый человек составляет: " + str + " рублей"); повторяется в каждой ветке, кроме слова рубль, лучше код вынести после if-else, оставив в нем только определение слова

}

}else{
System.out.println("Вы ввели некорректное значение. Пожалуйста, введите значение больше 1.");
Copy link

@MagicUnderHood MagicUnderHood Oct 29, 2022

Choose a reason for hiding this comment

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

Можно текст "Пожалуйста, введите значение больше 1." записать в константу, он повторяется 3 раза

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer

@MagicUnderHood MagicUnderHood MagicUnderHood left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /