Repository navigation
Expand file tree
/
Copy pathCalculate.java
More file actions
60 lines (47 loc) · 2.12 KB
/
Copy pathCalculate.java
File metadata and controls
60 lines (47 loc) · 2.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import java.util.Scanner;
public class Calculate {
public static void product(double person) {
String food = "";
double price = 0.0;
while (true) {
System.out.println("Для добавления товара введите название продукта\nДля завершения программы введите \"Завершить\"");
Scanner scanner = new Scanner(System.in);
String inputFood = scanner.next();
double itog = 0;
if (inputFood.equalsIgnoreCase("Завершить")) {
itog = (int) (price / person);
System.out.println("Покупка завершена, " + String.format("%.0f", person) + " персоны заплатят по " + itog + " " + Matsh.floover(itog));
break;
} else {
System.out.println("Введите стоимость продукта в формате \"'рубли.копейки' [10.45, 11.40]\"");
while (!scanner.hasNextInt()) {
System.out.println("Некорректное значение, введите стоимость продукта в формате \"'рубли.копейки' [10.45, 11.40]\"");
scanner.next();
}
float inputPrice = (float) scanner.nextDouble();
food = food + "\n" + inputFood;
price = price + inputPrice;
System.out.println("Вы успешно добавили продукт:" + food + "\nИтог: " + String.format("%.2f", price) + " " + Matsh.floover(itog));
}
}
}
static class Matsh {
public static String floover(double price) {
int amount = (int) price;
if (amount > 100)
amount %= 100;
if (amount > 20)
amount %= 10;
switch (amount) {
case 1:
return "Рублю";
case 2:
case 3:
case 4:
return "Рубля";
default:
return "Рублей";
}
}
}
}