-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathBasket.java
More file actions
40 lines (32 loc) · 871 Bytes
/
Basket.java
File metadata and controls
40 lines (32 loc) · 871 Bytes
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
package com.booleanuk.core;
import java.util.HashMap;
import java.util.Map;
public class Basket {
public Map<String, Integer> items;
public int max = 5;
public Basket() {
this.items = new HashMap<>();
}
public void addBagel(String type, int quantity) {
this.items.put(type, quantity);
}
public boolean removeBagel(String key) {
if (items.get(key) != null) {
items.remove(key);
return true;
}
else {
return false;
}
}
public boolean hasCapacity() {
int totalItemsInBasket = 0;
for (Map.Entry<String, Integer> item : items.entrySet()) {
totalItemsInBasket += item.getValue();
}
return totalItemsInBasket < max;
}
public void changeBasketCapacity(int limit) {
this.max = limit;
}
}