forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
87 lines (64 loc) · 2.85 KB
/
Main.java
File metadata and controls
87 lines (64 loc) · 2.85 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double rubl = 0;
String tovar = null;
double stoim = 0;
String spisokTovar = "Список товаров:\n";
double stoimSumma = 0;
int endHum = vodHuman();
System.out.println("Далее введите наименование и стоимость товара.");
while (true) {
System.out.println("Введите наименование товара:");
tovar = scanner.nextLine();
if (tovar.equalsIgnoreCase("Завершить")) {
break;
} else {
while (true) {
System.out.println("Введите стоимость товара:");
if (scanner.hasNextDouble()) {
stoim = scanner.nextDouble();
if (stoim > 0) {
spisokTovar += tovar + "\n";
stoimSumma += stoim;
System.out.println("Товар успешно добавлен.");
break;
} else {
System.out.println("Ошибка, необходимо вводить правильную цену.");
}
} else {
System.out.println("Ошибка, необходимо вводить правильную цену");
}
scanner.nextLine();
}
System.out.println("Введите следующий товар или \"Завершить\" для подсчета стоимости товаров.");
scanner.nextLine();
}
}
String endsum = String.format("%.2f", stoimSumma);
System.out.println(spisokTovar + "Сумма товаров:\n" + endsum);
rubl = stoimSumma / endHum;
Calc.getRubl(rubl);
}
public static int vodHuman() {
int human = 0;
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("На сколько человек разделить счёт:");
if (scanner.hasNextInt()) {
human = scanner.nextInt();
if (human <= 1) {
System.out.println("Значение не корректно, введите количество человек 2 или больше");
scanner.nextLine();
} else {
break;
}
} else {
System.out.println("Введите число");
scanner.nextLine();
}
}
return human;
}
}