-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrder.java
More file actions
47 lines (36 loc) · 1.17 KB
/
Order.java
File metadata and controls
47 lines (36 loc) · 1.17 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
package hashcode.model;
import java.util.HashMap;
import java.util.Map;
public class Order {
public static Order[] orders;
public int id;
public Point point;
public Map<Integer, Integer> products = new HashMap<Integer, Integer>();
public int weight;
public long points;
public int time;
public Order(int id, Point point) {
this.id = id;
this.point = point;
}
public void addProduct(int productId) {
products.put(productId, products.getOrDefault(productId, 0) + 1);
weight += ProductType.productTypes[productId].weight;
}
public void removeProduct(int productId) {
products.put(productId, products.get(productId) - 1);
weight -= ProductType.productTypes[productId].weight;
}
public void removeProduct(int productId, int amount) {
products.put(productId, products.get(productId) - amount);
weight -= ProductType.productTypes[productId].weight * amount;
}
@Override
public String toString() {
return "Order{" +
"id=" + id +
", point=" + point +
", products=" + products +
'}';
}
}