Repository navigation
Expand file tree
/
Copy pathResult.java
More file actions
58 lines (52 loc) · 2.04 KB
/
Copy pathResult.java
File metadata and controls
58 lines (52 loc) · 2.04 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
public class Result {
/// поля
private double rubValue; // итоговое значение вычислений
private String rubFormat; // переменная для хранения правильной формы слова "рубль"
// методы
public void setRubValue(double rub) {
rubValue = rub;
}
public void format() {
double rubRounded = Math.floor(rubValue);
if (rubValue >= 0 && rubValue <21) {
if (rubValue==0) {
rubFormat = "рублей";
} else if (rubValue == 1) {
rubFormat = "рубль";
} else if (rubValue >= 2 && rubValue <5) {
rubFormat = "рубля";
} else if (rubValue >=5) {
rubFormat = "рублей";
}
} else if (rubValue >= 21 && rubValue <100) {
if (rubRounded%10 == 1) {
rubFormat = "рубль";
} else if (rubRounded%10 > 1 && rubRounded%10 <5) {
rubFormat = "рубля";
} else if (rubRounded%10 >=5 || rubRounded%10 == 0) {
rubFormat = "рублей";
}
} else if (rubValue >=100) {
if (rubRounded % 100 == 0) {
rubFormat = "рублей";
} else if (rubRounded % 100 == 1) {
rubFormat = "рубль";
} else if (rubRounded % 100 > 1 && rubRounded % 100 <5) {
rubFormat = "рубля";
} else if (rubRounded % 100 >=5 && rubRounded % 100 < 21) {
rubFormat = "рублей";
} else {
if (rubRounded%10 == 1) {
rubFormat = "рубль";
} else if (rubRounded%10 > 1 && rubRounded%10 <5) {
rubFormat = "рубля";
} else if (rubRounded%10 >=5 || rubRounded%10 == 0) {
rubFormat = "рублей";
}
}
}
}
public String getRubFormat() {
return rubFormat;
}
}