-
Notifications
You must be signed in to change notification settings - Fork 220
Expand file tree
/
Copy pathMain.java
More file actions
87 lines (61 loc) · 3.02 KB
/
Main.java
File metadata and controls
87 lines (61 loc) · 3.02 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
import java.util.Locale;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// ваш код начнется здесь
// вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости
GoodCalculator gc = new GoodCalculator();
Scanner scanner = new Scanner(System.in);
scanner.useLocale(Locale.US);
int peopleNumber;
String contunieGoodAdding, resultSumPerPerson;
System.out.println("На скольких человек разделить счет?");
while (true) {
if (scanner.hasNextInt()) {
peopleNumber = scanner.nextInt();
if (peopleNumber > 1) {
break;
}
else {
System.out.println("Введите целое число больше 1:");
scanner.nextLine();
}
}
else {
System.out.println("Введите целое число больше 1:");
scanner.nextLine();
}
}
while (true) {
System.out.println("Введите название товара:");
scanner.nextLine();
gc.goodName = scanner.nextLine();
System.out.println("Введите стоимость товара [копейки.рубли] (например, 40.25):");
while (true) {
if (scanner.hasNextDouble()) {
gc.goodPrice = scanner.nextDouble();
if (gc.goodPrice > 0) {
break;
}
else {
System.out.println("Введите число больше 0:");
scanner.nextLine();
}
}
else {
System.out.println("Введите число больше 0:");
scanner.nextLine();
}
}
gc.addGood(gc.goodName, gc.goodPrice);
System.out.println("\n\nТовар успешно добавлен! Текущая общая сумма: " + gc.goodSumPrice + " " + gc.rubleEnding(gc.goodSumPrice));
System.out.println("Хотите добавить еще товар? Чтобы завершить, введите \'Завершить\'");
contunieGoodAdding = scanner.next();
if (contunieGoodAdding.equalsIgnoreCase("Завершить")) {
break;
}
}
resultSumPerPerson = String.format("%.2f" ,gc.goodSumPrice/peopleNumber);
System.out.println("\n\n" + gc.goodSumName + "\n\nОбщая сумма: " + gc.goodSumPrice + " " + gc.rubleEnding(gc.goodSumPrice) + "\nС каждого участника: " + resultSumPerPerson + " " + gc.rubleEnding(gc.goodSumPrice/peopleNumber));
}
}