forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator.java
More file actions
54 lines (48 loc) · 1.83 KB
/
Calculator.java
File metadata and controls
54 lines (48 loc) · 1.83 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.Scanner;
public class Calculator {
static int persons = 0;
static String menuSum = "";
static double priceSum = 0;
public static void calculator() {
Scanner scanner = new Scanner(System.in);
System.out.println("Введите количество человек:");
while (true) {
if (scanner.hasNextInt()) {
persons = scanner.nextInt();
if (persons < 2) {
System.out.println("Введите число больше 1");
} else {
break;
}
} else {
System.out.println("Введите целое число ");
scanner.next();
}
}
while (true) {
System.out.println("Введите название товара или введите 'Завершить', что бы выйти");
scanner.nextLine();
String menu = scanner.nextLine();
if (menu.equalsIgnoreCase("Завершить")) {
System.out.println("Товар успешно добавлен.");
break;
}
menuSum += menu + "\n";
while (true) {
System.out.println("Введите цену товара:");
if (scanner.hasNextDouble()) {
double price = scanner.nextDouble();
if (price > 0) {
priceSum += price;
break;
} else {
System.out.println("Введите число больше 0");
}
} else {
System.out.println("Введите число");
scanner.next();
}
}
}
}
}