Beispiel #1
0
        public void AddTopping(Topping top)
        {
            if (toppings.Count > MaxToppings)
            {
                throw new ArgumentException
                          (string
                          .Format(DefaultErrorMsgs
                                  .MaxToppingErrorMsg, MinToppings, MaxToppings));
            }

            toppings.Add(top);
        }
        public static void MakePizza(string[] tokens)
        {
            var numberToppings = int.Parse(tokens[2]);
            var pizza          = new Pizza(tokens[1], numberToppings);
            var doughInfo      = Console.ReadLine().Split(' ');
            var dough          = new Dough(doughInfo[1], doughInfo[2], double.Parse(doughInfo[3]));

            pizza.Dough = dough;

            for (var i = 0; i < numberToppings; i++)
            {
                var topInfo = Console.ReadLine().Split(' ');
                var topping = new Topping(topInfo[1], double.Parse(topInfo[2]));
                pizza.AddTopping(topping);
            }

            Console.WriteLine($"{pizza.Name} - {pizza.GetCalories():f2} Calories.");
        }
Beispiel #3
0
        public int OrderPizza(int pizzaid, string address, int transferprice)
        {
            int price = transferprice;

            try
            {
                Pizza p = pizzas.Where((x => x.Id == pizzaid)).First();
                price += p.Price;
                foreach (int top in p.toppings)
                {
                    Topping t = toppings.Where((x => x.Id == top)).First();
                    price += t.Price;
                }
            }
            catch (Exception e) { }
            orders.Add(new Order(pizzaid, address, price));
            new Thread(new ThreadStart(exportOrders));
            return(price);
        }
Beispiel #4
0
        private void LoadToppings()
        {
            XDocument toppingsdoc       = XDocument.Load("toppings.xml");
            IEnumerable <XElement> tops = toppingsdoc.Root.Elements("topping");

            toppings = new Topping[tops.Count()];
            int i = 0;

            foreach (XElement t in tops)
            {
                int    id    = Int32.Parse(t.Attribute("id").Value);
                string name  = t.Attribute("name").Value;
                int    price = Int32.Parse(t.Attribute("price").Value);
                toppings[i] = new Topping()
                {
                    Id = id, Name = name, Price = price
                };
                i++;
            }
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            try
            {
                string[] tokens = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);

                string name = String.Empty;
                if (tokens.Length == 2)
                {
                    name = tokens[1];
                }
                Pizza pizza = new Pizza(name);

                tokens = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
                string flourType       = tokens[1];
                string bakingTechnique = tokens[2];
                double weight          = double.Parse(tokens[3]);
                Dough  dough           = new Dough(flourType, bakingTechnique, weight);
                pizza.Dough = dough;

                tokens = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
                while (tokens[0] != "END")
                {
                    string  toppingType   = tokens[1];
                    double  toppingWeight = double.Parse(tokens[2]);
                    Topping topping       = new Topping(toppingType, toppingWeight);
                    pizza.AddTopping(topping);

                    tokens = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
                }
                Console.WriteLine(pizza.ToString());
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Beispiel #6
0
 public void AddTopping(Topping topping)
 {
     this.toppings.Add(topping);
 }
Beispiel #7
0
        static void Main(string[] args)
        {
            Pizza pizza;
            Dough dough;

            try
            {
                string[] pizzaInfo = Console.ReadLine().Split();
                string   pizzaName = pizzaInfo[1];
                pizza = new Pizza(pizzaName);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return;
            }

            try
            {
                string[] doughInfo  = Console.ReadLine().Split();
                string   flour      = doughInfo[1];
                string   bakingTech = doughInfo[2];
                double   weight     = double.Parse(doughInfo[3]);
                dough = new Dough(flour.ToLower(), bakingTech.ToLower(), weight);

                pizza.PizzaDough = dough;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return;
            }

            string toppingInfo;

            while ((toppingInfo = Console.ReadLine()) != "END")
            {
                try
                {
                    string[] toppingParams = toppingInfo.Split();

                    string  toppingName   = toppingParams[1].ToLower();
                    double  toppingWeight = double.Parse(toppingParams[2]);
                    Topping topping       = new Topping(toppingName, toppingWeight);

                    pizza.Add(topping);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    return;
                }
            }

            try
            {
                Console.WriteLine($"{pizza.Name} - {pizza.PizzaCalories():f2} Calories.");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return;
            }
        }
Beispiel #8
0
        public static void DebugRead()
        {
            var    input            = Console.ReadLine();
            var    pizzaInfo        = input.Split().Skip(1).ToArray();
            string pizzaName        = pizzaInfo[0];
            int    numberOfToppings = int.Parse(pizzaInfo[1]);

            try
            {
                var pizza = new Pizza(pizzaName, numberOfToppings);
                input = Console.ReadLine();

                while (input != "END")
                {
                    string[] line            = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    string   ingradientPizza = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(line[0].ToLower());

                    switch (ingradientPizza)
                    {
                    case "Dough":

                        var    tokens          = input.Split().Skip(1).ToArray();
                        string flourType       = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(tokens[0]);
                        string bakingTechnique = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(tokens[1]);
                        double weight          = double.Parse(tokens[2]);

                        try
                        {
                            var dough = new Dough(flourType, bakingTechnique, weight);
                            totalSUmCalories += dough.CaloriesPerGram;
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                            return;
                        }
                        break;

                    case "Topping":
                        var    toppingTokens = line.Skip(1).ToArray();
                        string toppingType   = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(toppingTokens[0]);
                        double toppingWeight = double.Parse(toppingTokens[1]);
                        if (numberOfToppings == 0)
                        {
                            Console.WriteLine("...");
                        }

                        numberOfToppings--;

                        try
                        {
                            var topping = new Topping(toppingType, toppingWeight);
                            totalSUmCalories += topping.CaloriesPerGram;
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                            return;
                        }

                        break;
                    }

                    input = Console.ReadLine();
                }

                Console.WriteLine($"{pizza.PizzaName} - {pizza.TotalCalories:F2} Calories.");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }