Advertisement
Guest User

Main

a guest
Mar 7th, 2019
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.83 KB | None | 0 0
  1. package PizzaCalories;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6.  
  7. public class Main {
  8.     public static void main(String[] args) throws IOException {
  9.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  10.  
  11.         String[] pizzaAndToppingsNumber = reader.readLine().split(" ");
  12.  
  13.         String pizzaName = pizzaAndToppingsNumber[1];
  14.         int numberOfToppings = Integer.parseInt(pizzaAndToppingsNumber[2]);
  15.  
  16.         Pizza pizza;
  17.         try {
  18.             pizza = new Pizza(pizzaName, numberOfToppings);
  19.         } catch (IllegalArgumentException ex) {
  20.             System.out.println(ex.getMessage());
  21.             return;
  22.         }
  23.  
  24.  
  25.         String[] doughInfo = reader.readLine().split(" ");
  26.  
  27.         String flourType = doughInfo[1];
  28.         String bakingTechnique = doughInfo[2];
  29.         int weight = Integer.parseInt(doughInfo[3]);
  30.  
  31.         Dough dough;
  32.         try {
  33.             dough = new Dough(flourType, bakingTechnique, weight);
  34.             pizza.setDough(dough);
  35.         } catch (IllegalArgumentException ex) {
  36.             System.out.println(ex.getMessage());
  37.             return;
  38.         }
  39.  
  40.  
  41.         String[] toppingInfo;
  42.         while (numberOfToppings-- > 0) {
  43.             toppingInfo = reader.readLine().split(" ");
  44.             String toppingType = toppingInfo[1];
  45.             double toppingWeight = Double.parseDouble(toppingInfo[2]);
  46.  
  47.             try {
  48.                 Topping topping = new Topping(toppingType, toppingWeight);
  49.                 pizza.addTopping(topping);
  50.             } catch (IllegalArgumentException ex) {
  51.                 System.out.println(ex.getMessage());
  52.                 return;
  53.             }
  54.         }
  55.  
  56.         System.out.printf("%s – %.2f", pizzaName, pizza.getOverallCalories());
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement