-
Notifications
You must be signed in to change notification settings - Fork 218
Expand file tree
/
Copy pathCalculator.java
More file actions
42 lines (36 loc) · 1.19 KB
/
Calculator.java
File metadata and controls
42 lines (36 loc) · 1.19 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
public class Calculator {
String bill = "";
double finalPrice = 0;
int countPerson = 0;
double priceOfPerson = 0;
public void setCountPerson(int countPerson) {
this.countPerson = countPerson;
}
public void setBill(Product product) {
bill += (product.getNameOfProduct() + " " + product.getCost()) + "\n";
finalPrice += product.getCost();
}
public String math() {
String rubles = "руб";
if (priceOfPerson > 10 && priceOfPerson <20 ) {
return rubles + "лей";
} switch ((int) priceOfPerson % 10) {
case 1: {
return rubles + "ль";
}
case 2:
case 3:
case 4: {
return rubles + "ля";
}
default: {
return rubles + "лей";
}
}
}
public void calculate() {
priceOfPerson = finalPrice / countPerson;
System.out.println("Количество персон: " + countPerson + "\n" + "Общий чек: " +
"\n" + bill + "\n" + "Денег с человека:" + "\n" + String.format("%.2f", priceOfPerson) + " " + math());
}
}