Repository navigation
Expand file tree
/
Copy pathCalculator.java
More file actions
84 lines (51 loc) · 2 KB
/
Copy pathCalculator.java
File metadata and controls
84 lines (51 loc) · 2 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.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Scanner;
public class Calculator {
private final int countPeople;
private double sum;
private double price;
private final List<Product> goods = new ArrayList<>();
Calculator(int countPeople) {
this.countPeople = countPeople;
}
public void total() {
DecimalFormat decimalFormat = new DecimalFormat("#.##");
System.out.println("Общая сумма " + decimalFormat.format(sum)+ " " + Product.GetRubleAddition(sum));
System.out.println("С человека " + decimalFormat.format(sum / countPeople) + " " +
Product.GetRubleAddition(sum / countPeople));
}
public void start(Scanner sc) {
while (true) {
System.out.println("Введите название товара");
String name = sc.next();
System.out.println("Введите цену товара");
while (true) {
Scanner scDouble = new Scanner(System.in).useLocale(Locale.US);
if (scDouble.hasNextDouble()){
price = scDouble.nextDouble();
sum += price;
break;
}else{
System.out.println("Неверный ввод, введите цену в формате 00.00");
}
}
Product product = new Product(name, price);
goods.add(product);
System.out.println("Товар добавлен, введи Завершить, чтобы закончить ввод");
String check = sc.next();
if (check.equalsIgnoreCase("Завершить")) {
break;
}
}
}
public void result() {
System.out.println("Добавленные товары: ");
for (Product product : goods
) {
product.info();
}
}
}