Beispiel #1
0
        public void Adds_toppings_to_pizza()
        {
            var expected = new List <string>()
            {
                "test 1", "test 2"
            };

            target.AddToppings(expected);
            Assert.IsTrue(target.Toppings.All(t => expected.Contains(t)));
        }
    static void Main(string[] args)
    {
        try
        {
            var inputInfo = Console.ReadLine().Split();
            var pizzaName = inputInfo[1];

            var pizza = new Pizza(pizzaName);

            var inputDoughInfo = Console.ReadLine().Split();
            var pizzaDough     = new Dough(inputDoughInfo[1], inputDoughInfo[2], double.Parse(inputDoughInfo[3]));
            pizza.Dough = pizzaDough;

            string inputToppingInfo;
            while ((inputToppingInfo = Console.ReadLine()) != "END")
            {
                var parts          = inputToppingInfo.Split();
                var currentTopping = new Topping(parts[1], double.Parse(parts[2]));

                pizza.AddToppings(currentTopping);
            }

            Console.WriteLine($"{pizza.Name} - {pizza.TotalCaloriesInPizza():f2} Calories.");
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message); return;
        }
    }
        public void Run()
        {
            try
            {
                string[] pizzaInfo   = Console.ReadLine().Split();
                string[] doughtInfo  = Console.ReadLine().Split();
                string   pizzaName   = pizzaInfo[1];
                string   doughType   = doughtInfo[1];
                string   doughModel  = doughtInfo[2];
                double   weightDough = double.Parse(doughtInfo[3]);

                Pizza pizza = new Pizza(pizzaName);

                pizza.AddDough(doughType, doughModel, weightDough);

                string input;

                while ((input = Console.ReadLine()) != END_INGRIDIENTS)
                {
                    string[] toppingInfo   = input.Split();
                    string   toppingType   = toppingInfo[1];
                    double   weightTopping = double.Parse(toppingInfo[2]);
                    Topping  topping       = new Topping(toppingType, weightTopping);
                    pizza.AddToppings(topping);
                }

                Console.WriteLine(pizza);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.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);
        }
    }
        public void Run()
        {
            string[] pizzaData = ConsoleReader();
            string[] doughData = ConsoleReader();
            Dough    dough     = CreateDough(doughData);
            Pizza    pizza     = CreatePizza(pizzaData, dough);
            string   input     = string.Empty;

            while ((input = Console.ReadLine()) != "END")
            {
                string[] toppingData = input.Split().ToArray();
                Topping  topping     = CreateTopping(toppingData);
                pizza.AddToppings(topping);
            }
            Console.WriteLine(pizza);
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            Console.WriteLine("What kind of candy are you eating?");
            var candyName = Console.ReadLine();

            Console.WriteLine("How many are you going to eat?");
            var amount = int.Parse(Console.ReadLine());

            var candy = new Candy(candyName, amount);

            candy.Eat();

            candy.Share();


            Console.WriteLine("What would you like on your pizza?");
            var myToppings  = Console.ReadLine();
            var toppingList = myToppings.Split(",");

            Console.WriteLine("What kind of crust would you like?");
            var crust = Console.ReadLine();

            var myPizza = new Pizza(16, crust);

            myPizza.AddToppings(toppingList);
            myPizza.CrustSelector(crust);

            var myDog = new Dog("Golden Retriever", "Woofles");

            myDog.Walk();

            myDog.Brag();

            var myFavTeam = new Football("Packers", "1-0");

            myFavTeam.CheckRecord();

            myFavTeam.BandWagon();
        }
Beispiel #7
0
    static void Main(string[] args)
    {
        try
        {
            var   pizzaInfo     = Console.ReadLine().Split();
            var   doughInfo     = Console.ReadLine().Split();
            Dough currentDought = new Dough(flourType: doughInfo[1], bakingTechnique: doughInfo[2], weight: double.Parse(doughInfo[3]));

            Pizza currentPizza = new Pizza(name: pizzaInfo[1], dough: currentDought);
            var   toppingInfo  = new string[3];
            while ((toppingInfo = Console.ReadLine().Split())[0] != "END")
            {
                Topping currentTopping = new Topping(type: toppingInfo[1], weight: double.Parse(toppingInfo[2]));
                currentPizza.AddToppings(currentTopping);
            }

            Console.WriteLine($"{currentPizza.Name} - {currentPizza.CalcTotalCalories():f2} Calories.");
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
        }
    }
        static void Main(string[] args)
        {
            //declaring variables
            Pizza  newPizza, newPizza2;
            string userInput;

            Console.WriteLine("This is the Pizza Factory program.\nHere is an object creation of 2 Pizzas.\n\n");

            newPizza  = new Pizza("M", 5, "wheat");
            newPizza2 = new Pizza("L", 1, "white");

            Console.WriteLine("Two Pizzas have been created. These foods inherit the food class, allowing access to parental functionality, such as the GetNutrition method.\n\n");

            // Inherited method coming from the parent class Food.
            newPizza.GetNutrition();
            newPizza2.GetNutrition();

            Console.WriteLine("Method isSoftOrSolid() is an abstract method from the IFood interface." +
                              " This method has not been defined yet, so when called, it will throw an Exception.\n" +
                              "Enter 1 to enter the exception, or any other key to continue.\n\n");

            //Take user input
            userInput = Console.ReadLine();

            //add TryCatch here to validate user input
            try
            {
                if (Convert.ToInt32(userInput) == 1)
                {
                    newPizza.IsSoftOrSolid();
                }
            } catch (Exception e)
            {
                Console.WriteLine("You entered a non-numeric entry. Please try again.\n" + e.Message + "\n");
            }

            Console.WriteLine("Temperature is an abstract property, implemented from the IFood interface." +
                              " This property is defined in the Pizza class, and is currently: " + "j" + "\n");

            //newPizza.temp;

            //add TryCatch here to validate second user input
            Console.WriteLine("Add toppings to the pizza.");
            userInput = Console.ReadLine();
            newPizza.AddToppings(userInput);


            /*    Console.Write("To attempt to add these toppings w/o first converting the returned string value to an integer " +
             *      "(due to C# requires that every non-null value have a well-defined type associated with it," +
             *      "thus causing an unhandled exception to occur, press 1." +
             *      "\nPress any other key to first do the parsing and properly add the toppings to the numberOfToppings property.");
             *
             *  userInput = Console.ReadLine();
             *
             *  if (userInput.Equals(1))
             *  {
             *      Console.WriteLine("Adding ");
             *  }
             *  newPizza.addToppings(int.Parse(userInput));
             */
        }
    static void Main(string[] args)
    {
        string input = Console.ReadLine();
        bool   flag  = false;

        string[] tokens = input.Split();
        string   name   = tokens[1];

        if (name.Length <= 15 && name.Length >= 1)
        {
            input  = Console.ReadLine();
            tokens = input.Split();
            string flourType       = tokens[1];
            string bakingTechnique = tokens[2];
            int    weight          = int.Parse(tokens[3]);
            if ((bakingTechnique.ToLower() == "crispy" || bakingTechnique.ToLower() == "chewy" ||
                 bakingTechnique.ToLower() == "homemade") &&
                (flourType.ToLower() == "white" || flourType.ToLower() == "wholegrain") &&
                (weight >= 1 && weight <= 200))
            {
                Pizza pizza = new Pizza(name, new Dough(flourType, bakingTechnique, weight));
                pizza.name                  = name;
                pizza.dough                 = new Dough(flourType, bakingTechnique, weight);
                pizza.dough.flourType       = flourType;
                pizza.dough.bakingTechnique = bakingTechnique;
                pizza.dough.weight          = weight;
                input = Console.ReadLine();
                while (input != "END")
                {
                    tokens = input.Split();
                    pizza.AddToppings(new Toppings(tokens[1], int.Parse(tokens[2])));
                    if (pizza.toppings.Last().name != tokens[1] ||
                        pizza.toppings.Last().weight != int.Parse(tokens[2]))
                    {
                        flag = true;
                        break;
                    }
                    input = Console.ReadLine();
                }
                if (!flag)
                {
                    PrintCalories(pizza);
                }
            }
            else
            {
                if (weight < 1 || weight > 15)
                {
                    Console.WriteLine("Dough weight should be in the range [1..200].");
                }
                else
                {
                    Console.WriteLine("Invalid type of dough.");
                }
            }
        }
        else
        {
            Console.WriteLine("Pizza name should be between 1 and 15 symbols.");
        }
    }