Guest User

Untitled

a guest
Mar 11th, 2020
216
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package E04_PizzaCalories;
  2.  
  3. public class Topping {
  4. private String toppingType;
  5. private double weight;
  6.  
  7.  
  8. public Topping(String toppingType, double weight) {
  9. this.setToppingType(toppingType);
  10. this.setWeight(weight);
  11. }
  12.  
  13. private void setToppingType(String toppingType) {
  14. if (!TypeUtils.TOPPING_TYPES.containsKey(toppingType)){
  15. throw new IllegalArgumentException("Cannot place "+ toppingType +" on top of your pizza.");
  16. }
  17. this.toppingType = toppingType;
  18. }
  19.  
  20. private void setWeight(double weight) {
  21. if (weight < 1 || weight > 50){
  22. throw new IllegalArgumentException(this.toppingType + " weight should be in the range [1..50].");
  23. }
  24. this.weight = weight;
  25. }
  26.  
  27.  
  28. public double calculateCalories (){
  29. return this.weight * 2 * TypeUtils.TOPPING_TYPES.get(toppingType);
  30. }
  31. }
RAW Paste Data