-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathBasket.java
More file actions
69 lines (59 loc) · 1.65 KB
/
Basket.java
File metadata and controls
69 lines (59 loc) · 1.65 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
package com.booleanuk.core;
import java.util.ArrayList;
public class Basket {
ArrayList<String> basket;
public int capacity;
public Basket(){
this.basket = new ArrayList<>();
this.capacity = 5;
}
public boolean checkIfNotFull(){
if(this.basket == null){
return false;
}
if(this.basket.size() > this.capacity){
System.out.println("Basket is full, unable to add bagel!");
return false;
}
System.out.println("Basket is not full, adding bagel");
return true;
}
public String tryRemoveBagel(String bagel){
if (!this.basket.contains(bagel)) {
System.out.println("Bagel not in list");
return "Bagel not in list";
}
System.out.println("Bagel is removed from list");
this.basket.remove(bagel);
return "Bagel is removed from list";
}
public int changeCapacity(int capacity){
if(capacity < 0 ){
System.out.println("Invalid capacity, setting default capacity of 5");
return this.capacity = 5;
}
return this.capacity = capacity;
}
public boolean remove(String bagel) {
if(bagel == null){
return false;
}
if(!this.basket.contains(bagel)){
return false;
}
this.tryRemoveBagel(bagel);
return true;
}
public boolean add(String bagel){
if(bagel == null){
return false;
}
if(bagel.isEmpty()){
return false;
}
if(checkIfNotFull()){
basket.add(bagel);
}
return true;
}
}