Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package PizzaCalories2;
- public class Dough {
- private String flourType; //white, wholegrain
- private String bakingTechnique; //crispy, chewy, homemade
- private double weight;
- public Dough(String flourType, String bakingTechnique, double weight) {
- setFlourType(flourType);
- setBakingTechnique(bakingTechnique);
- setWeight(weight);
- }
- private void setFlourType(String flourType) {
- if (flourType.isEmpty()) {
- throw new IllegalArgumentException("Invalid type of dough.");
- }
- if (!flourType.equals("White") && !flourType.equals("Wholegrain")) {
- throw new IllegalArgumentException("Invalid type of dough.");
- }
- this.flourType = flourType;
- }
- private void setBakingTechnique(String bakingTechnique) {
- if (bakingTechnique.isEmpty()) {
- throw new IllegalArgumentException("Invalid type of dough.");
- }
- if (!bakingTechnique.equals("Crispy") && !bakingTechnique.equals("Chewy")
- && !bakingTechnique.equals("Homemade")) {
- throw new IllegalArgumentException("Invalid type of dough.");
- }
- this.bakingTechnique = bakingTechnique;
- }
- private void setWeight(double weight) {
- if (weight < 1.0 || weight > 200.0) {
- throw new IllegalArgumentException("Dough weight should be in the range [1..200].");
- }
- this.weight = weight;
- }
- public double calculateCalories() {
- double calories = 0;
- switch (this.flourType) {
- case "White":
- calories = (2 * this.weight) * 1.5;
- break;
- case "Wholegrain":
- calories = (2 * this.weight) * 1.0;
- default:
- break;
- }
- switch (this.bakingTechnique) {
- case "Crispy":
- calories *= 0.9;
- break;
- case "Chewy":
- calories *= 1.1;
- break;
- case "Homemade":
- calories *= 1.0;
- break;
- default:
- break;
- }
- return calories;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement