I'm trying to create a Pizza menu. I have 3 classes,
- PizzaBase (with get / set methods for the thickness of the base [either thin or deeppan])
- PizzaTopping, again with get / set methods for the type of topping
- Pizza, where my cost variable is stored and used across the 3 classes using inheritance.
As a cost variable is used for the base, the topping and the overall pizza itself.
Now my question is this, how would I go about creating a Pizza object, which in turn creates 1 base object, and a few toppings objects, each with a price?
I can work out how to calculate an overall price, I'm just a bit stuck creating objects within objects.
public class PizzaTopping extends Pizza{
private String topping;
public String getTopping(){
return this.topping;
}
public void setTopping( String topping ){
this.topping = topping;
}
}
public class PizzaBase extends Pizza{
private String base;
public void setBase( String base ){
this.base = base;
}
public String getBase(){
return this.base;
}
}
public class Pizza {
private double cost;
public void setCost( double cost ){
this.cost = Math.abs(cost);
}
public double getCost(){
return this.cost;
}
public void makingPizza(){
PizzaBase b = new PizzaBase();
}
}
PizzaToppingextendPizza? APizzais composed ofPizzaToppings; aPizzaToppingis not aPizzaitself. I would rethink the object model.String topping. It's not really any more special than that.