package PizzaCalories2; import java.util.ArrayList; import java.util.List; public class Pizza { private String name; private Dough dough; private List toppings; public Pizza(String name, int toppingsCount) { // implement setName(name); setToppings(toppingsCount); } private void setToppings(int toppingsCount) { if (toppingsCount < 0 || toppingsCount > 10) { throw new IllegalArgumentException("Number of toppings should be in range [0..10]."); } this.toppings = new ArrayList<>(toppingsCount); } private void setName(String name) { if (name.isEmpty() || name.length() > 15 || name.contains(" ")) { throw new IllegalArgumentException("Pizza name should be between 1 and 15 symbols."); } this.name = name; } public void setDough(Dough dough) { this.dough = dough; } public void addTopping(Topping topping) { this.toppings.add(topping); } public double getOverallCalories() { double calories = 0; for (Topping topping : this.toppings) { calories += topping.calculateCalories(); } calories += this.dough.calculateCalories(); return calories; } //override tostring? }