Repository navigation
Expand file tree
/
Copy pathMain.java
More file actions
84 lines (65 loc) · 2.61 KB
/
Copy pathMain.java
File metadata and controls
84 lines (65 loc) · 2.61 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
import java.util.Scanner;
public class Main {
static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
System.out.print("Добро пожаловать в систему совместных закупок!\n");
getPeopleCount();
getGoods();
Calculator.printCheck();
}
static void getPeopleCount() {
int peopleCount;
System.out.print("Сколько человек будет приобретать товары?\n");
while (true) {
if (scanner.hasNextInt()) {
int input = scanner.nextInt();
if (input >= 2) {
peopleCount = input;
break;
} else {
System.out.print("Ошибка: неверный ввод!\n");
}
} else {
System.out.print("Ошибка: неверный ввод!\n");
scanner.next();
}
}
Calculator.peopleCount = peopleCount;
}
static void getGoods() {
String goodLabel;
double goodPrice;
System.out.print("Введите название товара:\n");
goodLabel = scanner.next();
while (true) {
System.out.print("Введите стоимость товара [" + goodLabel + "] в формате: \"руб.коп\", например [10.45, 11.40]:\n");
while (true) {
if (scanner.hasNextDouble()) {
double input = scanner.nextDouble();
if (isRightFormat(input)) {
goodPrice = input;
break;
} else {
System.out.print("Ошибка: неверный ввод!\n");
}
} else {
System.out.print("Ошибка: неверный ввод!\n");
scanner.next();
}
}
Calculator.addNewGood(new Good(goodLabel, goodPrice));
System.out.print("Введите название товара, или введите \"Завершить\", чтобы закончить:\n");
String input = scanner.next();
if (input.equalsIgnoreCase("Завершить")) {
break;
} else {
goodLabel = input;
}
}
}
static boolean isRightFormat (Double d) {
String[] splitter = String.valueOf(d).split("[.]");
int l = splitter[1].length();
return (d > 0) && (l <= 2);
}
}