Feat: Decorator implemented
This commit is contained in:
50
src/entities/Kebab.java
Normal file
50
src/entities/Kebab.java
Normal file
@@ -0,0 +1,50 @@
|
||||
package entities;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Kebab {
|
||||
private String name;
|
||||
private double price;
|
||||
private List<Addon> addons;
|
||||
|
||||
public Kebab(String name, double price) {
|
||||
this.name = name;
|
||||
this.price = price;
|
||||
this.addons = new ArrayList<>();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
StringBuilder name = new StringBuilder();
|
||||
|
||||
name.append(this.name);
|
||||
|
||||
for (Addon addon : addons) {
|
||||
name.append(", ");
|
||||
name.append(addon.getName());
|
||||
}
|
||||
|
||||
return name.toString();
|
||||
}
|
||||
|
||||
public double getPrice() {
|
||||
double price = 0.0d;
|
||||
|
||||
for (Addon addon : addons) {
|
||||
price += addon.getPrice();
|
||||
}
|
||||
return price + this.price;
|
||||
}
|
||||
|
||||
public void addIngredient(Addon addon) {
|
||||
addons.add(addon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Kebab{" +
|
||||
"name='" + getName() + '\'' +
|
||||
", price=" + getPrice() +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user