Repository navigation
Expand file tree
/
Copy pathMain.java
More file actions
58 lines (41 loc) · 1.83 KB
/
Copy pathMain.java
File metadata and controls
58 lines (41 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
50
51
52
53
54
55
56
57
58
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
short participantsQuantity = 0;
String breakDeсision = "Завершить";
while (participantsQuantity <= 1) {
System.out.println("На скольких человек необходимо разделить счет?");
if (scanner.hasNextShort()) {
participantsQuantity = scanner.nextShort();
} else {
scanner.next();
}
if (participantsQuantity <= 1) {
System.out.println("Количество участников дожно быть число больше 1");
}
}
Calculator calc = new Calculator(participantsQuantity);
String userDeсision = "";
while (!userDeсision.equalsIgnoreCase(breakDeсision)) {
System.out.println("Введите название товара (руб,коп)");
String product = scanner.next();
float cost = 0f;
while (cost <= 0) {
System.out.println("Введите стоимость");
if (scanner.hasNextFloat()) {
cost = scanner.nextFloat();
} else {
scanner.next();
}
if (cost <= 0) {
System.out.println("Сmоимость товара должно быть число больше нуля!");
}
}
calc.addProduct(product, cost);
System.out.println("Добавить ещё один товар? (Если это всё, введите \"" + breakDeсision + "\")");
userDeсision = scanner.next();
}
calc.calculate();
}
}