-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathBasket.java
More file actions
108 lines (68 loc) · 1.89 KB
/
Basket.java
File metadata and controls
108 lines (68 loc) · 1.89 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
package com.booleanuk.core;
import com.booleanuk.core.Items.Bagel;
import com.booleanuk.core.Items.Item;
import java.util.ArrayList;
import java.util.List;
public class Basket {
public static int capacity = 8;
private Inventory storeInventory;
private List<Item> itemsInBasket = new ArrayList<>();
public Basket(){
}
public int getCapacity() {
return capacity;
}
public boolean setCapacity(int capacity) {
if(capacity>0) {
Basket.capacity = capacity;
return true;
}
return false;
}
public Inventory getStoreInventory() {
return storeInventory;
}
public void setStoreInventory(Inventory storeInventory) {
this.storeInventory = storeInventory;
}
public List<Item> getItemsInBasket() {
return itemsInBasket;
}
public void setItemsInBasket(List<Item> itemsInBasket) {
this.itemsInBasket = itemsInBasket;
}
public double sum(){
double sum = 0;
for (Item item : itemsInBasket) {
sum+=item.getPrice();
}
return sum;
}
public boolean add(Item i)throws NullPointerException{
if(i.getID() == null || i.getID().isEmpty() || i.getVariant().isEmpty() || i.getPrice()<=0)
return false;
return this.itemsInBasket.add(i);
}
public boolean remove(Item i){
return this.itemsInBasket.remove(i);
}
public boolean isFull() {
return this.itemsInBasket.size() == capacity;
}
public Item getItem(Item i){
return i;
}
public double costOfBagel(Item i){
return i.getPrice();
}
public Bagel getBagel(){
for (Item i: this.itemsInBasket){
if (i instanceof Bagel)
return (Bagel)i;
}
return null;
}
public boolean hasDiscount(){
return false;
}
}