Advertisement
Guest User

Dough

a guest
Mar 9th, 2019
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.20 KB | None | 0 0
  1. package PizzaCalories2;
  2.  
  3. public class Dough {
  4.     private String flourType; //white, wholegrain
  5.     private String bakingTechnique; //crispy, chewy, homemade
  6.     private double weight;
  7.  
  8.     public Dough(String flourType, String bakingTechnique, double weight) {
  9.         setFlourType(flourType);
  10.         setBakingTechnique(bakingTechnique);
  11.         setWeight(weight);
  12.     }
  13.  
  14.     private void setFlourType(String flourType) {
  15.         if (flourType.isEmpty()) {
  16.             throw new IllegalArgumentException("Invalid type of dough.");
  17.         }
  18.  
  19.         if (!flourType.equals("White") && !flourType.equals("Wholegrain")) {
  20.             throw new IllegalArgumentException("Invalid type of dough.");
  21.         }
  22.  
  23.         this.flourType = flourType;
  24.     }
  25.  
  26.     private void setBakingTechnique(String bakingTechnique) {
  27.         if (bakingTechnique.isEmpty()) {
  28.             throw new IllegalArgumentException("Invalid type of dough.");
  29.         }
  30.  
  31.         if (!bakingTechnique.equals("Crispy") && !bakingTechnique.equals("Chewy")
  32.                 && !bakingTechnique.equals("Homemade")) {
  33.             throw new IllegalArgumentException("Invalid type of dough.");
  34.  
  35.         }
  36.         this.bakingTechnique = bakingTechnique;
  37.     }
  38.  
  39.     private void setWeight(double weight) {
  40.         if (weight < 1.0 || weight > 200.0) {
  41.             throw new IllegalArgumentException("Dough weight should be in the range [1..200].");
  42.         }
  43.         this.weight = weight;
  44.     }
  45.  
  46.     public double calculateCalories() {
  47.         double calories = 0;
  48.  
  49.         switch (this.flourType) {
  50.             case "White":
  51.                 calories = (2 * this.weight) * 1.5;
  52.                 break;
  53.             case "Wholegrain":
  54.                 calories = (2 * this.weight) * 1.0;
  55.             default:
  56.                 break;
  57.         }
  58.  
  59.         switch (this.bakingTechnique) {
  60.             case "Crispy":
  61.                 calories *= 0.9;
  62.                 break;
  63.             case "Chewy":
  64.                 calories *= 1.1;
  65.                 break;
  66.             case "Homemade":
  67.                 calories *= 1.0;
  68.                 break;
  69.             default:
  70.                 break;
  71.         }
  72.  
  73.         return calories;
  74.     }
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement