public class PizzaLager { public static void main(String[] args) { Pizza pizza = new CheesePizza(); System.out.println("Pris:" + pizza.getCost() + "\n" + pizza.getTopping() + "\n\n\n"); pizza = new LeggTilDressing(pizza); System.out.println("Pris:" + pizza.getCost() + "\n" + pizza.getTopping() + "\n\n\n"); pizza = new LeggTilKylling(pizza); System.out.println("Pris:" + pizza.getCost() + "\n" + pizza.getTopping() + "\n\n\n"); pizza = new LeggTilPepperoni(pizza); System.out.println("Pris:" + pizza.getCost() + "\n" + pizza.getTopping()); } } interface Pizza { double getCost(); String getTopping(); } class CheesePizza implements Pizza { @Override public double getCost() { return 150; //kostnad for en enkelt pizza med ost } @Override public String getTopping() { return "Ingredients:\n- Cheese"; //Hva toppingen best?r av } } abstract class PizzaDecorator implements Pizza { private final Pizza pizza; public PizzaDecorator(Pizza pizza) { this.pizza = pizza; } @Override public double getCost() { return pizza.getCost(); } @Override public String getTopping() { return pizza.getTopping(); } } class LeggTilKylling extends PizzaDecorator { public LeggTilKylling(Pizza pizza) { super(pizza); } @Override public double getCost() { return super.getCost() + 35; } @Override public String getTopping() { return super.getTopping() + "\n- Chicken"; } } class LeggTilOst extends PizzaDecorator { public LeggTilOst(Pizza pizza) { super(pizza); } @Override public double getCost() { return super.getCost() + 20; } @Override public String getTopping() { return super.getTopping() + "\n- Extra Cheese"; } } class LeggTilDressing extends PizzaDecorator { public LeggTilDressing(Pizza pizza) { super(pizza); } @Override public double getCost() { return super.getCost() + 15; } @Override public String getTopping() { return super.getTopping() + "\n- Garlic Sauce"; } } class LeggTilPepperoni extends PizzaDecorator { public LeggTilPepperoni(Pizza pizza) { super(pizza); } @Override public double getCost() { return super.getCost() + 30; } @Override public String getTopping() { return super.getTopping() + "\n- Pepperoni"; } }