Advertisement
Guest User

Dough

a guest
Mar 7th, 2019
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.58 KB | None | 0 0
  1. package PizzaCalories;
  2.  
  3. import java.util.HashMap;
  4. import java.util.Map;
  5.  
  6. public class Dough {
  7.     private String flourType;
  8.     private String bakingTechnique;
  9.     private double weight;
  10.  
  11.     private final Map doughType = new HashMap<String, Double>() {{
  12.         put("White", 1.5);
  13.         put("Wholegrain", 1.0);
  14.     }};
  15.  
  16.     private final Map techniques = new HashMap<String, Double>() {{
  17.         put("Crispy", 0.9);
  18.         put("Chewy", 1.1);
  19.         put("Homemade", 1.0);
  20.     }};
  21.  
  22.     public Dough(String flourType, String technique, double weight) {
  23.         setFlourType(flourType);
  24.         setBakingTechnique(technique);
  25.         setWeight(weight);
  26.     }
  27.  
  28.     private void setFlourType(String flourType) {
  29.         if (!doughType.containsKey(flourType)) {
  30.             throw new IllegalArgumentException("Invalid type of dough.");
  31.         }
  32.         this.flourType = flourType;
  33.     }
  34.  
  35.     private void setBakingTechnique(String bakingTechnique) {
  36.         if (!techniques.containsKey(bakingTechnique)) {
  37.             throw new IllegalArgumentException("Invalid type of dough.");
  38.         }
  39.         this.bakingTechnique = bakingTechnique;
  40.     }
  41.  
  42.     private void setWeight(double weight) {
  43.         if (weight < 1 || weight > 200) {
  44.             throw new IllegalArgumentException("Dough weight should be in the range [1..200].");
  45.         }
  46.         this.weight = weight;
  47.     }
  48.  
  49.     public double calculateCalories() {
  50.         return (double) doughType.get(this.flourType)
  51.                 * (double)techniques.get(this.bakingTechnique) * (2 * this.weight);
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement