Feat: Decorator implemented

This commit is contained in:
Namu
2025-10-22 23:15:15 +02:00
commit 349cdb484e
13 changed files with 301 additions and 0 deletions

50
src/entities/Kebab.java Normal file
View 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() +
'}';
}
}