Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test;
- import java.util.HashMap;
- import java.util.Map;
- public class Dough {
- private String doughType;
- private String doughProperty;
- private Double doughWeight;
- private static Map<String, Double> doughTypes = new HashMap<>();
- private static Map<String, Double> doughProperties = new HashMap<>();
- public static void mapOfDoughTypes() {
- doughTypes.put("White", 1.5);
- doughTypes.put("Wholegrain", 1.0);
- }
- public static void mapOfDoughProperties() {
- doughProperties.put("Crispy", 0.9);
- doughProperties.put("Chewy", 1.1);
- doughProperties.put("Homemade", 1.0);
- }
- private Map<String, Double> getDoughTypes() {
- return doughTypes;
- }
- public Dough() {
- this.doughType = "";
- this.doughProperty = "";
- this.doughWeight = -1.0;
- }
- public Dough(String doughType, String doughProperty, Double doughWeight) {
- if (!doughTypes.containsKey(doughType) || !doughProperties.containsKey(doughProperty)){
- throw new IllegalArgumentException("Invalid type of dough.");
- }
- // DOT HERE
- if (doughWeight < 1 || doughWeight > 200) {
- throw new IllegalArgumentException("Dough weight should be in the range [1..200].");
- }
- this.doughType = doughType;
- this.doughProperty = doughProperty;
- this.doughWeight = doughWeight;
- }
- public void setDoughType(String doughType) {
- if (!doughTypes.containsKey(doughType)){
- throw new IllegalArgumentException("Invalid type of dough.");
- }
- this.doughType = doughType;
- }
- public void setDoughProperty(String doughProperty) {
- if (!doughProperties.containsKey(doughProperty)){
- throw new IllegalArgumentException("Invalid type of dough.");
- }
- this.doughProperty = doughProperty;
- }
- public String getDoughType() {
- return doughType;
- }
- public String getDoughProperty() {
- return doughProperty;
- }
- private Double getDoughTypeModiffier(){
- return doughTypes.get(this.doughType);
- }
- private Double getDoughPropertyModiffier(){
- return doughProperties.get(this.doughProperty);
- }
- public double doughCalories(){
- return (2*this.doughWeight)*this.getDoughTypeModiffier()*this.getDoughPropertyModiffier();
- }
- }
- package test;
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- public class Main {
- public static void main(String[] args) throws Exception {
- BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
- try {
- String input = bufferedReader.readLine();
- int toppingNumber = Integer.parseInt(input.split(" ")[2]);
- Pizza pizza = new Pizza(input.split(" ")[1], toppingNumber);
- Dough.mapOfDoughProperties();
- Dough.mapOfDoughTypes();
- Topping.mapOfToppingTypes();
- while (true) {
- input = bufferedReader.readLine();
- if (input.equals("END")) {
- break;
- }
- switch (input.split(" ")[0]) {
- case "Dough":
- Dough dough = new Dough(input.split(" ")[1], input.split(" ")[2]
- , Double.parseDouble(input.split(" ")[3]));
- pizza.setDough(dough);
- break;
- case "Topping":
- Topping topping = new Topping(input.split(" ")[1],
- Double.parseDouble(input.split(" ")[2]));
- pizza.setToppings(topping);
- break;
- }
- }
- System.out.printf("%s - %.2f%n", pizza.getName(), pizza.calculateCalories());
- } catch (IllegalArgumentException iae) {
- System.out.println(iae.getMessage());
- }
- }
- }
- package test;
- import java.util.LinkedList;
- import java.util.List;
- // Toppings from 0 to 10
- // Name trim
- public class Pizza {
- private String name;
- private Dough dough;
- private int numberOfTopping;
- private List<Topping> toppings;
- public Pizza(String name, int numberOfTopping) {
- if(name.trim().length() < 1 || name.trim().length() > 15) {
- throw new IllegalArgumentException("Pizza name should be between 1 and 15 symbols.");
- }
- if(numberOfTopping < 0 || numberOfTopping > 10) {
- throw new IllegalArgumentException("Number of toppings should be in range [0..10].");
- }
- this.name = name;
- this.dough = new Dough();
- this.toppings = new LinkedList<>();
- this.numberOfTopping = numberOfTopping;
- }
- public void setDough(Dough dough) {
- this.dough = dough;
- }
- public void setToppings(Topping topping) {
- this.toppings.add(topping);
- }
- public String getName() {
- return name;
- }
- public Dough getDough() {
- return dough;
- }
- public List<Topping> getToppings() {
- return toppings;
- }
- public double calculateCalories() {
- Double doughCalories = this.dough.doughCalories();
- Double toppingCalories = 0.0;
- for (Topping topping : toppings) {
- toppingCalories = toppingCalories + topping.caloriesTopping();
- }
- return doughCalories + toppingCalories;
- }
- }
- package test;
- import java.util.HashMap;
- import java.util.Map;
- // Dot in toppings weight
- public class Topping {
- private String toppingName;
- private Double weightTopping;
- private static Map<String, Double> toppingTypes = new HashMap<>();
- public static void mapOfToppingTypes() {
- toppingTypes.put("Meat", 1.2);
- toppingTypes.put("Veggies", 0.8);
- toppingTypes.put("Cheese", 1.1);
- toppingTypes.put("Sauce", 0.9);
- }
- public Topping() {
- this.toppingName = "";
- }
- public Topping(String toppingName, double weightTopping) {
- if (!toppingTypes.containsKey(toppingName)) {
- throw new IllegalArgumentException("Cannot place " + toppingName + " on top of your pizza.");
- }
- if (weightTopping < 1 || weightTopping > 50) {
- throw new IllegalArgumentException(toppingName + " weight should be in the range [1..50].");
- }
- this.weightTopping = weightTopping;
- this.toppingName = toppingName;
- }
- public void setToppingName(String toppingName) {
- if (!toppingTypes.containsKey(toppingName)) {
- throw new IllegalArgumentException("Cannot place " + toppingName + " on top of your pizza.");
- }
- this.toppingName = toppingName;
- }
- public void setWeightTopping(double weightTopping) {
- if (weightTopping < 1 || weightTopping > 50) {
- throw new IllegalArgumentException(toppingName + " weight should be in the range [1..50].");
- }
- this.weightTopping = weightTopping;
- }
- private double getToppingModifier() {
- return toppingTypes.get(this.toppingName);
- }
- public double caloriesTopping(){
- return (2*this.weightTopping)*this.getToppingModifier();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement