forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator.java
More file actions
28 lines (24 loc) · 853 Bytes
/
Calculator.java
File metadata and controls
28 lines (24 loc) · 853 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
public class Calculator {
public String getRubleAddition(double num) {
int preLastDigit = (int) ((num % 100) / 10);
if (preLastDigit == 1) {
return "рублей";
} else {
switch ((int) (num % 10)) {
case 1:
return "рублю";
case 2:
case 3:
case 4:
return "рубля";
default:
return "рублей";
}
}
}
void calculate(double totalAmount, int numberOfPersons) {
double payBill = totalAmount / numberOfPersons;
String SumForOnePerson = "Каждый должен оплатить по: %.2f";
System.out.println(String.format(SumForOnePerson, payBill) + " " + getRubleAddition(payBill));
}
}