-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathBagel.java
More file actions
79 lines (66 loc) · 1.84 KB
/
Bagel.java
File metadata and controls
79 lines (66 loc) · 1.84 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
package com.booleanuk.core;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class Bagel implements Item{
private List<Filling> fillings = new ArrayList<>();
private String variant;
private String name;
private String sku;
private float price;
public Bagel(String variant) {
this.variant = variant.toUpperCase();
this.name = "Bagel";
this.price = 0.49F;
setRest();
}
private void setRest(){
switch (this.variant) {
case "ONION" -> this.sku = "BGLO";
case "PLAIN" -> {
this.price = 0.39F;
this.sku = "BGLP";
}
case "EVERYTHING" -> this.sku = "BGLE";
case "SESAME" -> this.sku = "BGLS";
}
}
@Override
public String getVariant() {
return this.variant;
}
@Override
public float getPrice(){
float totalPrice = this.price;
if (!fillings.isEmpty()){
for (Filling filling : fillings) {
totalPrice += filling.getPrice();
}
}
return totalPrice;
}
@Override
public String getSku() {
return this.sku;
}
@Override
public String getName() {
return this.name;
}
public void addFilling(String filling){
String addFilling = filling.toUpperCase();
fillings.add(new Filling(addFilling));
}
public List<Filling>getFillings() {
return fillings;
}
public boolean removeFilling(String filling) {
String fillingToRemove = filling.toUpperCase();
for(Filling fillingInList: fillings){
if (fillingInList.getVariant().equals(fillingToRemove)){
fillings.remove(fillingInList);
return true;
}
}return false;
}
}