Repository navigation
Expand file tree
/
Copy pathMain.java
More file actions
44 lines (33 loc) · 1.7 KB
/
Copy pathMain.java
File metadata and controls
44 lines (33 loc) · 1.7 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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int persons;
double pricePerPersons = 0;
while (true) {
System.out.print("Введите количество человек: ");
if (scanner.hasNextInt()) {
persons = scanner.nextInt();
if (persons >= 2) {
break;
} else if (persons == 1) {
System.out.println("Вы за столом один. Пригласите друзей и попробуйте снова.");
} else if (persons <= 0) {
System.out.println("Число персон не может быть отрицательным или нулевым. Попробуйте снова.");
}
} else {
System.out.println("Введено некорректное значение. Попробуйте снова.");
scanner.next();
}
}
Calculator calculator = new Calculator();
calculator.calculate();
// тест System.out.println(calculator.totalProductPrice);
Formater formater = new Formater();
// formater.formater(calculator.totalProductPrice);
// System.out.println((calculator.totalProductPrice) + (formater.formater(calculator.totalProductPrice)));
pricePerPersons = calculator.totalProductPrice / persons;
formater.formater(pricePerPersons);
System.out.println("Цена на одного человека: " + String.format("%.2f", pricePerPersons) + " " + formater.formater(pricePerPersons));
}
}