Example #1
0
    static void Main()
    {
        string inputLine;

        while ((inputLine = Console.ReadLine()) != "END")
        {
            var tokens = inputLine.Split(' ');

            try
            {
                switch (tokens[0])
                {
                case "Dough":
                    var dough = new Dough(tokens[1], tokens[2], double.Parse(tokens[3]));
                    Console.WriteLine($"{dough.GetCalories():f2}");
                    break;

                case "Topping":
                    var topping = new Topping(tokens[1], double.Parse(tokens[2]));
                    Console.WriteLine($"{topping.GetCalories():f2}");
                    break;

                case "Pizza":
                    MakePizza(tokens);
                    break;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return;
            }
        }
    }
 public static void Main()
 {
     try
     {
         string input;
         while ((input = Console.ReadLine()) != "END")
         {
             var tokens = input.Split();
             if (tokens[0].ToLower() == "dough")
             {
                 var dough = new Dough(tokens[1], tokens[2], double.Parse(tokens[3]));
                 Console.WriteLine($"{dough.GetCalories():F2}");
             }
             else if (tokens[0].ToLower() == "topping")
             {
                 var topping = new Topping(tokens[1], double.Parse(tokens[2]));
                 Console.WriteLine($"{topping.GetCalories():F2}");
             }
             else if (tokens[0].ToLower() == "pizza")
             {
                 MakePizza(tokens);
                 break;
             }
         }
     }
     catch (ArgumentException argumentException)
     {
         Console.WriteLine(argumentException.Message);
     }
 }
    static void Main(string[] args)
    {
        try
        {
            var inputLine = Console.ReadLine();

            while (inputLine != "END")
            {
                var linePerts = inputLine.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                if (linePerts[0] == "Dough")
                {
                    var newDough = new Dough(linePerts[1], linePerts[2], double.Parse(linePerts[3]));
                    Console.WriteLine($"{newDough.GetCalories():f2}");
                }
                else if (linePerts[0] == "Topping")
                {
                    var newTopping = new Topping(linePerts[1], double.Parse(linePerts[2]));
                    Console.WriteLine($"{newTopping.GetCalories():f2}");
                }
                else if (linePerts[0] == "Pizza")
                {
                    var pizzaName        = linePerts[1];
                    var numberOfToppings = int.Parse(linePerts[2]);

                    if (numberOfToppings > 10)
                    {
                        Console.WriteLine("Number of toppings should be in range [0..10].");
                        return;
                    }

                    var input = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    var dough = new Dough(input[1], input[2], double.Parse(input[3]));
                    var pizza = new Pizza(pizzaName, dough);

                    for (int i = 0; i < numberOfToppings; i++)
                    {
                        var lineTopingInfo = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        pizza.AddToppings(new Topping(lineTopingInfo[1], double.Parse(lineTopingInfo[2])));
                    }

                    Console.WriteLine($"{pizza.Name} - {pizza.GetTotalcalories():f2} Calories.");
                }


                inputLine = Console.ReadLine();
            }
        }
        catch (ArgumentException ex)
        {
            Console.WriteLine(ex.Message);
        }
    }
Example #4
0
 static void Main()
 {
     try
     {
         Topping topping = new Topping("meat", 30);
         Console.WriteLine(topping.GetCalories());
     }
     catch (ArgumentException e)
     {
         Console.WriteLine(e.Message);
     }
 }
Example #5
0
    private static void CalculatePizzaCalories()
    {
        var inpit = Console.ReadLine().Split();

        try
        {
            while (inpit[0] != "END")
            {
                switch (inpit[0].ToLower())
                {
                case "pizza":
                    var pizza = SetPizza(inpit[1], int.Parse(inpit[2]));
                    Console.WriteLine(pizza.GetTotalCalories());
                    break;

                case "dough":
                    var douugh = new Dough(inpit[1], inpit[2], int.Parse(inpit[3]));
                    Console.WriteLine($"{douugh.GetCalories():F2}");
                    break;

                case "topping":
                    var toppint = new Topping(inpit[1], int.Parse(inpit[2]));
                    Console.WriteLine($"{toppint.GetCalories():F2}");
                    break;

                default:
                    break;
                }

                inpit = Console.ReadLine().Split();
            }
        }
        catch (ArgumentException ex)
        {
            Console.WriteLine(ex.Message);
        }
    }