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

New PR#1

Open
GRUsik wants to merge 4 commits intomain from
dev
Open

New PR #1
GRUsik wants to merge 4 commits intomain from
dev

Conversation

@GRUsik
Copy link
Owner

@GRUsik GRUsik commented May 1, 2023

Новый PR


}

if (people > 1) {
Copy link

@ilshat-abdulin ilshat-abdulin May 2, 2023

Choose a reason for hiding this comment

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

🍏 Эту проверку можно убрать. Все проверки у тебя делаются в цикле в try-catch

System.out.println("Введите количество гостей: ");
} catch (final InputMismatchException e) {
System.out.println("Введено некорректное значение\nВведите количество гостей: ");
continue;
Copy link

@ilshat-abdulin ilshat-abdulin May 2, 2023

Choose a reason for hiding this comment

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

🍏 Можно без continue. Цикл и так продолжит работу

String product = "";
String allProducts = "";
double allCost = 0.00;
void Calculature() {
Copy link

@ilshat-abdulin ilshat-abdulin May 2, 2023

Choose a reason for hiding this comment

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

🍏 Именовать методы лучше с маленькой буквы. А с большой буквы именую обычно классы, интерфейсы

пункт 5 - https://habr.com/ru/articles/513176/

Comment on lines 53 to 59
case 5:
case 6:
case 7:
case 8:
case 9:
System.out.println("Счет на каждого гостя равен: " + result + "рублей");
break;
Copy link

@ilshat-abdulin ilshat-abdulin May 2, 2023

Choose a reason for hiding this comment

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

🍏 Для этой проверки ((int) shet % 10), можно объединить оставшиеся значения, кроме 1-4, в default

 switch ((int) shet % 10) {
 case 1:
 System.out.println("Счет на каждого гостя равен: " + result + " рубль");
 break;
 case 2:
 case 3:
 case 4:
 System.out.println("Счет на каждого гостя равен: " + result + " рубля");
 break;
 default:
 System.out.println("Счет на каждого гостя равен: " + result + "рублей");
 }

System.out.println("Итоговая сумма заказа: " + calculature.allCost);
shet = calculature.allCost / people;
String result = String.format("%.2f",shet);
switch ((int) shet%10) {
Copy link

@ilshat-abdulin ilshat-abdulin May 2, 2023

Choose a reason for hiding this comment

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

⚠ Если, например, итоговая сумма после расчета будет равна 114, то получится 114,00 рубля. Или если будет 11, то 11,00 рубль.
image

Нужно дополнительно учесть, что для чисел 11-19 должно быть "рублей" - для этого стоит проверять, что <число> % 100 расположено между 11 и 19 включительно. Эту проверку можно сделать через if-else

🍏 Для удобства, рекомендую вынести логику расчета правильного окончания в отдельный метод.

shet = calculature.allCost / people;
String result = String.format("%.2f",shet);
switch ((int) shet%10) {
switch ((int) shet%100) {
Copy link

@ilshat-abdulin ilshat-abdulin May 4, 2023

Choose a reason for hiding this comment

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

⚠ К сожалению, не сработало) В некоторых случаях, ни один из кейсов не подходит и сообщение с словом "рубль" не выводится
image

Попробуй сделать так, чтобы учесть все возможные варианты

 // сначала проверяем, что остаток деления на 100 находится между 11..14
 if ((int) shet % 100 >= 11 && (int) shet % 100 <= 14) {
 System.out.println("Счет на каждого гостя равен: " + result + " рублей");
 } else {
 // если условие выше не сработало, то проверяем остаток от 10
 
 switch ((int) shet % 10) {
 case 1:
 System.out.println("Счет на каждого гостя равен: " + result + " рубль");
 break;
 case 2:
 case 3:
 case 4:
 System.out.println("Счет на каждого гостя равен: " + result + " рубля");
 break;
 default:
 System.out.println("Счет на каждого гостя равен: " + result + " рублей");
 break;
 }
 }

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

Reviewers

1 more reviewer

@ilshat-abdulin ilshat-abdulin ilshat-abdulin 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 によって変換されたページ (->オリジナル) /