Repository navigation
Expand file tree
/
Copy pathCalculator.java
More file actions
59 lines (52 loc) · 2.04 KB
/
Copy pathCalculator.java
File metadata and controls
59 lines (52 loc) · 2.04 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
import java.util.Scanner;
public class Calculator {
static double sum = 0.0;
// Добавление товаров в список
static void goodsInput() {
Scanner sc = new Scanner(System.in);
while (true) {
System.out.println("Введите название товара.");
String name = sc.next(); // ?
double cost = 0.0;
while (true) {
System.out.println("Введите стоимость товара.");
if (sc.hasNextDouble()) {
cost = sc.nextDouble();
if (cost > 0.0) {
sum += cost;
break;
}
} else {
System.out.println("ОШИБКА! Вы указали некорректное значение.");
sc.next();
}
}
Goods.list = Goods.list + " " + name + " " + Double.toString(cost) + "\n";
System.out.println("Товар успешно добавлен!");
System.out.println("Хотите ввести следующий товар или завершить?");
if (end()) {
break;
}
}
sc.close();
System.out.println("Добавленные товары:");
System.out.print(Goods.list);
System.out.println("===================");
sc.close();
}
// Расчет итоговой суммы
static void totalAmount(int people) {
sum /= people;
System.out.println("Итоговая сумма: " + Formatter.rounding(sum) + " " + Formatter.rubles(sum) + ".");
}
// Обрабатываем случай, если вводят слово ЗАВЕРШИТЬ.
static boolean end() {
Scanner sc = new Scanner(System.in);
String input = sc.nextLine();
if (input.equalsIgnoreCase("завершить")) {
return true;
} else {
return false;
}
}
}