Advertisement
Guest User

Untitled

a guest
Mar 11th, 2020
444
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. package E04_PizzaCalories;
  2.  
  3. public class Dough {
  4. private String flourType;
  5. private String bakingTechnique;
  6. private double weight;
  7.  
  8. public Dough(String flourType, String bakingTechnique, double weight) {
  9. this.setFlourType(flourType);
  10. this.setBakingTechnique(bakingTechnique);
  11. this.setWeight(weight);
  12. }
  13.  
  14. private void setFlourType(String flourType) {
  15. if (!TypeUtils.DOUGH_TYPES.containsKey(flourType)){
  16. throw new IllegalArgumentException("Invalid type of dough.");
  17. }
  18. this.flourType = flourType;
  19. }
  20.  
  21. private void setBakingTechnique(String bakingTechnique) {
  22. if (!TypeUtils.BAKING_TECHNIQUES.containsKey(bakingTechnique)){
  23. throw new IllegalArgumentException("Invalid type of dough.");
  24. }
  25. this.bakingTechnique = bakingTechnique;
  26. }
  27.  
  28. private void setWeight(double weight) {
  29. if (weight < 1 || weight > 200){
  30. throw new IllegalArgumentException("Dough weight should be in the range [1..200].");
  31. }
  32. this.weight = weight;
  33. }
  34.  
  35. public double calculateCalories (){
  36. return 2 * this.weight * TypeUtils.DOUGH_TYPES.get(flourType) * TypeUtils.BAKING_TECHNIQUES.get(bakingTechnique);
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement