-
Notifications
You must be signed in to change notification settings - Fork 0
ДЗ на проверку #1
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: main
Are you sure you want to change the base?
Conversation
src/main/java/Main.java
Outdated
| public static String getPadejOfRubl (double sum) { | ||
|
|
||
| double i = Math.floor(sum % 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.
⚠ Если сумма на каждого гостя получится, например, 114, то в консоль будет выведено - 114.00 рубля.
Лучше дополнительно учесть, что для чисел в пределах 11-19 - должно быть "рублей". Для этого стоит проверять, что остаток от <число> % 100, находится включительно между 11 и 19
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.
Согласен, не додумал, исправлю
src/main/java/Main.java
Outdated
| if (i == 1) { return "рубль"; } | ||
| else if (i >= 2 && i <= 4) { return "рубля"; } | ||
| else { return "рублей"; } |
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.
🍏 Вместо такого стейтмента из if else-if, можно использовать switch case
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.
Я думал об этом, но не придумал как перечислить диапазон от 2 до 4 в switch case
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.
Можно так
case 1:
return " рубль.";
case 2:
case 3:
case 4:
return " рубля.";
Вместо else будет default:
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.
Да, я именно так и подумал сделать теперь) Спасибо за подсказку
| public class AdvancedScanner { | ||
| Scanner scan = new Scanner(System.in); |
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.
Логика этого класса выглядит, как эффективное и универсальное решение, для обработки введенных значений в консоль. Круто 👍
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.
Спасибо :)
Калькулятор готов