Guest User

Untitled

a guest
Mar 11th, 2020
204
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package E04_PizzaCalories;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5.  
  6. public class Pizza {
  7. private String name;
  8. private Dough dought;
  9. private List<Topping> toppings;
  10.  
  11. public Pizza(String name, int toppings) {
  12. this.setName(name);
  13. this.setToppings(toppings);
  14. }
  15.  
  16. private void setToppings(int toppings) {
  17. if (toppings < 0 || toppings > 10) {
  18. throw new IllegalArgumentException("Number of toppings should be in range [0..10].");
  19. }
  20. this.toppings = new ArrayList<>(toppings);
  21. }
  22.  
  23. public String getName() {
  24. return name;
  25. }
  26.  
  27. private void setName(String name) {
  28. if (name == null || name.trim().isEmpty() || name.trim().length() > 15) {
  29. throw new IllegalArgumentException("Pizza name should be between 1 and 15 symbols.");
  30. }
  31.  
  32. this.name = name;
  33. }
  34.  
  35. public void setDough(Dough dought) {
  36.  
  37. this.dought = dought;
  38. }
  39.  
  40. public void addTopping(Topping topping) {
  41. toppings.add(topping);
  42. }
  43.  
  44. public double getOverallCalories() {
  45. return dought.calculateCalories() * toppings.stream()
  46. .mapToDouble(Topping::calculateCalories)
  47. .sum();
  48. }
  49. }
RAW Paste Data