-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathBasket.java
More file actions
40 lines (29 loc) · 978 Bytes
/
Basket.java
File metadata and controls
40 lines (29 loc) · 978 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.ArrayList;
public class Basket {
private final int DEFAULT_CAPACITY = 10; // Assuming basket has capacity of 10 from beginning
ArrayList<String> bagels;
private int capacity;
public Basket() {
this.bagels = new ArrayList<>();
this.capacity = this.DEFAULT_CAPACITY;
}
public boolean add(String bagel) {
if (this.bagels.contains(bagel) || this.bagels.size() == this.capacity) {
return false;
}
this.bagels.add(bagel);
return true;
}
public boolean remove(String bagel) {
return this.bagels.remove(bagel);
}
public boolean isFull() {
return this.bagels.size() == this.capacity;
}
public boolean changeCapacity(int newCapcity, int userType) {
if (newCapcity < 0 || newCapcity < this.bagels.size() || userType != 0) return false;
this.capacity = newCapcity;
return true;
}
}