Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package E04_PizzaCalories;
- public class Dough {
- private String flourType;
- private String bakingTechnique;
- private double weight;
- public Dough(String flourType, String bakingTechnique, double weight) {
- this.setFlourType(flourType);
- this.setBakingTechnique(bakingTechnique);
- this.setWeight(weight);
- }
- private void setFlourType(String flourType) {
- if (!TypeUtils.DOUGH_TYPES.containsKey(flourType)){
- throw new IllegalArgumentException("Invalid type of dough.");
- }
- this.flourType = flourType;
- }
- private void setBakingTechnique(String bakingTechnique) {
- if (!TypeUtils.BAKING_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 2 * this.weight * TypeUtils.DOUGH_TYPES.get(flourType) * TypeUtils.BAKING_TECHNIQUES.get(bakingTechnique);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement