-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathBasket.java
More file actions
52 lines (44 loc) · 1.24 KB
/
Basket.java
File metadata and controls
52 lines (44 loc) · 1.24 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
package com.booleanuk.core;
import java.util.ArrayList;
public class Basket {
ArrayList<String> bagels = new ArrayList<String>();
ArrayList<String> orderedBagels = new ArrayList<>();
int capacity;
Basket(){
bagels.add("bagelOne");
bagels.add("bagelTwo");
bagels.add("bagelThree");
capacity = 5;
}
public boolean order(String bagel){
if(!bagels.contains(bagel)){
full();
System.out.println("Bagel not found!");
return false;
}
orderedBagels.add(bagel);
System.out.println("Bagel added.");
return true;
}
public boolean remove(String bagel){
if(orderedBagels.contains(bagel)){
orderedBagels.remove(bagel);
System.out.println("Bagel removed.");
return true;
}
System.out.println("Bagel not found!");
return false;
}
public boolean full(){
if(orderedBagels.size() >= capacity){
System.out.println("Basket is full!");
return true;
}
System.out.println("Basket is not full.");
return false;
}
public boolean setCapacity(int newCap){
capacity = newCap;
return true;
}
}