forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormatter.java
More file actions
38 lines (34 loc) · 1.12 KB
/
Formatter.java
File metadata and controls
38 lines (34 loc) · 1.12 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
public class Formatter {
double amount;
int persons;
String ending = " ";
String byPerson = "с человека";
Formatter(double amount, int persons) {
this.amount = amount;
this.persons = persons;
}
void printPrice() {
double perPerson = this.amount / this.persons;
if (perPerson < 1) {
ending += "рубля";
} else if ((perPerson % 100) >= 11 && (perPerson % 100) <= 19) {
ending += "рублей";
} else {
int reminderOfDivision = (int) Math.round(this.amount / this.persons % 10);
switch (reminderOfDivision) {
case 1:
ending += "рубль";
break;
case 2:
case 3:
case 4:
ending += "рубля";
break;
default:
ending += "рублей";
break;
}
}
System.out.println(String.format("%.2f", perPerson) + ending + " " + byPerson);
}
}