Repository navigation
Expand file tree
/
Copy pathMain.java
More file actions
105 lines (76 loc) · 3.93 KB
/
Copy pathMain.java
File metadata and controls
105 lines (76 loc) · 3.93 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import java.util.Scanner;
public class Main {
private static boolean isNumber(String value) {
try {
Integer.parseInt(value);
return true;
} catch (NumberFormatException ex) {
return false;
}
}
private static boolean isDouble(String value) {
try {
Double.parseDouble(value);
return true;
} catch (NumberFormatException ex) {
return false;
}
}
public static void main(String[] args) {
//После запуска программа должна спрашивать у пользователя, на скольких человек необходимо разделить счёт.
int numberPeople;
while (true) {
Scanner scanner = new Scanner(System.in);
System.out.println("Введите количество людей (больше или равно 1)");
String value = scanner.next();
boolean isNumber = isNumber(value);
if (isNumber) {
numberPeople = Integer.parseInt(value);
if (numberPeople == 1) {
System.out.println("Нет смысла ничего считать и делить.");
} else if (numberPeople < 1) {
System.out.println("Это некорректное значение для подсчёта.");
} else if (numberPeople > 1) {
break;
}
} else {
System.out.println("Введите корректное количество гостей.");
}
}
//Запросите у пользователя название товара и его стоимость.
Calculator calculator = new Calculator();
double costGoods = 0;
while (true) {
Scanner scannerr = new Scanner(System.in);
System.out.println("Введите название товара");
String productName = scannerr.nextLine();
while (true) {
System.out.println("Введите стоимость товара (в формате руб.копейки) ");
String costG = scannerr.next();
boolean isDouble = isDouble(costG);
if (isDouble) {
costGoods = Double.parseDouble(costG);
if (costGoods < 1) {
System.out.println("Это некорректное значение для подсчёта.");
} else if (costGoods > 0) {
break;
}
} else {
System.out.println("Введите корректное количество стоимость товара.");
}
}
calculator.addProduct(productName, costGoods);
System.out.println("Товар успешно добавлен");
calculator.countingGoods( numberPeople, costGoods);
System.out.println("Хотите добавить еще один товар или Завершить?");
String addOrFinish = scannerr.next();
if (addOrFinish.equalsIgnoreCase("Завершить")) {
System.out.println("Все добавленные товары : " +
"\n " + calculator.product +
"\n" + "Общая сумма счета :" + " " +Formatter.roundingCostProduct(calculator.totalPrice)+" "+Formatter.rubleCorrectCase(calculator.totalPrice) +
"\n" + "Сумма счета на каждого человека :" + " " +Formatter.roundingCostProduct(calculator.personalAmount)+" "+ Formatter.rubleCorrectCase(calculator.personalAmount));
break;
}
}
}
}