Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package E04_PizzaCalories;
- import java.util.ArrayList;
- import java.util.List;
- public class Pizza {
- private String name;
- private Dough dought;
- private List<Topping> toppings;
- public Pizza(String name, int toppings) {
- this.setName(name);
- this.setToppings(toppings);
- }
- private void setToppings(int toppings) {
- if (toppings < 0 || toppings > 10) {
- throw new IllegalArgumentException("Number of toppings should be in range [0..10].");
- }
- this.toppings = new ArrayList<>(toppings);
- }
- public String getName() {
- return name;
- }
- private void setName(String name) {
- if (name == null || name.trim().isEmpty() || name.trim().length() > 15) {
- throw new IllegalArgumentException("Pizza name should be between 1 and 15 symbols.");
- }
- this.name = name;
- }
- public void setDough(Dough dought) {
- this.dought = dought;
- }
- public void addTopping(Topping topping) {
- toppings.add(topping);
- }
- public double getOverallCalories() {
- return dought.calculateCalories() * toppings.stream()
- .mapToDouble(Topping::calculateCalories)
- .sum();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement