Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package PizzaCalories;
- import java.util.HashMap;
- import java.util.Map;
- public class Dough {
- private String flourType;
- private String bakingTechnique;
- private double weight;
- private final Map doughType = new HashMap<String, Double>() {{
- put("White", 1.5);
- put("Wholegrain", 1.0);
- }};
- private final Map techniques = new HashMap<String, Double>() {{
- put("Crispy", 0.9);
- put("Chewy", 1.1);
- put("Homemade", 1.0);
- }};
- public Dough(String flourType, String technique, double weight) {
- setFlourType(flourType);
- setBakingTechnique(technique);
- setWeight(weight);
- }
- private void setFlourType(String flourType) {
- if (!doughType.containsKey(flourType)) {
- throw new IllegalArgumentException("Invalid type of dough.");
- }
- this.flourType = flourType;
- }
- private void setBakingTechnique(String bakingTechnique) {
- if (!techniques.containsKey(bakingTechnique)) {
- throw new IllegalArgumentException("Invalid type of dough.");
- }
- this.bakingTechnique = bakingTechnique;
- }
- private void setWeight(double weight) {
- if (weight < 1 || weight > 200) {
- throw new IllegalArgumentException("Dough weight should be in the range [1..200].");
- }
- this.weight = weight;
- }
- public double calculateCalories() {
- return (double) doughType.get(this.flourType)
- * (double)techniques.get(this.bakingTechnique) * (2 * this.weight);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement