-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasket.java
More file actions
117 lines (92 loc) · 2.84 KB
/
Copy pathBasket.java
File metadata and controls
117 lines (92 loc) · 2.84 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
106
107
108
109
110
111
112
113
114
115
116
117
public class Basket {
private static int count = 0;
private static int costAllBasket = 0;
private static int countAllProdBasket = 0;
private String items = "";
private int totalPrice = 0;
private int limit;
private double totalWeight = 0;
public Basket() {
increaseCount(1);
items = "Список товаров:";
this.limit = 1000000;
}
public Basket(int limit) {
this();
this.limit = limit;
}
public Basket(String items, int totalPrice, double totalWeight) {
this();
this.items = this.items + items;
this.totalPrice = totalPrice;
this.totalWeight = totalWeight;
}
public static int getCount() {
return count;
}
public static void increaseCount(int count) {
Basket.count = Basket.count + count;
}
public static int getCountAllProdBasket() {
return countAllProdBasket;
}
public static void increaseCountAllProdBasket(int count) {
countAllProdBasket += count;
}
public static int getCostAllBasket() {
return costAllBasket;
}
public static void increaseCostAllBasket(int cost) {
costAllBasket += cost;
}
public static int getAveragePriceAllBasket() {
return costAllBasket / countAllProdBasket;
}
public static int getAverageCostBasket() {
return costAllBasket / getCount();
}
public void add(String name, int price) {
add(name, price, 1);
}
public void add(String name, int price, int count) {
boolean error = contains(name);
if (totalPrice + count * price >= limit) {
error = true;
}
if (error) {
System.out.println("Error occured :(");
return;
}
totalPrice = totalPrice + count * price;
increaseCountAllProdBasket(count);
increaseCostAllBasket(count * price);
items = items + "\n" + name + " - " +
count + " шт. - " + price + "\n" + "Общая стоимость товаров: " + totalPrice;
}
public void add(String name, int price, int count, double weight) {
totalWeight = totalWeight + weight * count;
items = "\n" + "Масса всех товаров корзине: " + totalWeight;
}
public void clear() {
items = "";
totalPrice = 0;
totalWeight = 0;
}
public int getTotalPrice() {
return totalPrice;
}
public double getTotalWeght() {
return totalWeight;
}
public boolean contains(String name) {
return items.contains(name);
}
public void print(String title) {
System.out.println(title);
if (items.isEmpty()) {
System.out.println("Корзина пуста");
} else {
System.out.println(items);
}
}
}