-
Notifications
You must be signed in to change notification settings - Fork 0
Comments
Conversation
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.
🍏 Эту проверку можно убрать. Все проверки у тебя делаются в цикле в try-catch
src/main/java/Main.java
Outdated
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.
🍏 Можно без continue. Цикл и так продолжит работу
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.
🍏 Именовать методы лучше с маленькой буквы. А с большой буквы именую обычно классы, интерфейсы
пункт 5 - https://habr.com/ru/articles/513176/
src/main/java/Main.java
Outdated
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.
🍏 Для этой проверки ((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 + "рублей");
}
src/main/java/Main.java
Outdated
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.
⚠ Если, например, итоговая сумма после расчета будет равна 114, то получится 114,00 рубля. Или если будет 11, то 11,00 рубль.
image
Нужно дополнительно учесть, что для чисел 11-19 должно быть "рублей" - для этого стоит проверять, что <число> % 100 расположено между 11 и 19 включительно. Эту проверку можно сделать через if-else
🍏 Для удобства, рекомендую вынести логику расчета правильного окончания в отдельный метод.
src/main/java/Main.java
Outdated
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.
⚠ К сожалению, не сработало) В некоторых случаях, ни один из кейсов не подходит и сообщение с словом "рубль" не выводится
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;
}
}
Новый PR