Repository navigation
Expand file tree
/
Copy pathCalculator.java
More file actions
49 lines (41 loc) · 1.66 KB
/
Copy pathCalculator.java
File metadata and controls
49 lines (41 loc) · 1.66 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
import java.util.InputMismatchException;
import java.util.Scanner;
public class Calculator {
static void calculate(int people) {
String food = "";
double price = 0.0;
while (true) {
System.out.println("Введите название продукта, для выхода введите [Завершить]");
Scanner scanner = new Scanner(System.in);
String inputFood = scanner.next();
if (inputFood.equalsIgnoreCase("Завершить")) {
break;
} else {
food = food + inputFood + "\n";
price = price + price();
}
}
int rouble = (int) Math.round(price);
System.out.println("Добавленные товары:\n" + food);
String message = "Каждый человек должен заплатить %.2f" + " " + Main.declination(rouble);
System.out.println(String.format(message, (price / people)));
}
static double price() {
while (true) {
System.out.println("Введите цену в формате [руб,коп]");
double inputPrice = 0;
try {
double price = 0.0;
Scanner scanner = new Scanner(System.in);
inputPrice = scanner.nextDouble();
if (inputPrice <= 0){
System.out.println("Неверное значение");
} else {
return inputPrice;
}
} catch (InputMismatchException e) {
System.out.println("Неверное значение");
}
}
}
}