Exemplo n.º 1
0
        public string PrintStatus()
        {
            if (this.tables.Count == 0)
            {
                return(Message.NoSales);
            }
            StringBuilder output = new StringBuilder();

            output.AppendLine(string.Format(Message.TotalTablesMsg, this.tables.Count));
            output.AppendLine(string.Format(Message.TotalSales, this.sales, this.money));
            output.AppendLine(Message.ByCategory);

            var tup = (1, 4m);

            tup.Item1 += 2;
            tup.Item2 += 5;

            Dictionary <string, (int count, decimal price)> grouped = new Dictionary <string, (int count, decimal price)>();

            foreach (var table in tables)
            {
                foreach (Orders order in table.Value)
                {
                    foreach (Product product in order.Products)
                    {
                        var category = product switch
                        {
                            Salad _ => "Салата",
                            Soup _ => "Супа",
                            MainDish _ => "Основно ястие",
                            Dessert _ => "Десерт",
                            Beverage _ => "Напитка",
                         _ => "No Category"
                        };

                        if (grouped.ContainsKey(category))
                        {
                            var newCount = grouped[category].count + 1;
                            var newPrice = grouped[category].price + product.Price;
                            grouped[category] = (newCount, newPrice);
                        }
                        else
                        {
                            grouped.Add(category, (1, product.Price));
                        }
                    }
                }
            }
            foreach (var entry in grouped)
            {
                output.AppendLine($"  -  {entry.Key}: {entry.Value.count} - {entry.Value.price:F2}");
            }
            return(output.ToString().Trim('\n', '\r'));
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            string[]       input        = Console.ReadLine().Split(new string[] { ", " }, StringSplitOptions.None).ToArray();
            List <Product> menuProducts = new List <Product>();
            Dictionary <int, List <Product> > orders = new Dictionary <int, List <Product> >();


            while (!int.TryParse(input[0], out int random))
            {
                string  type   = input[0];
                string  name   = input[1];
                int     weight = int.Parse(input[2]);
                decimal price  = decimal.Parse(input[3]);

                if (type == "MainDish")
                {
                    MainDish mainDish = new MainDish();
                    mainDish.Type   = type;
                    mainDish.Name   = name;
                    mainDish.Weight = weight;
                    mainDish.Price  = price;
                    menuProducts.Add(mainDish);
                }
                else if (type == "Drink")
                {
                    Drink drink = new Drink();
                    drink.Type   = type;
                    drink.Name   = name;
                    drink.Weight = weight;
                    drink.Price  = price;
                    menuProducts.Add(drink);
                }
                else if (type == "Desert")
                {
                    Desert desert = new Desert();
                    desert.Type   = type;
                    desert.Name   = name;
                    desert.Weight = weight;
                    desert.Price  = price;
                    menuProducts.Add(desert);
                }
                else if (type == "Salad" || type == "Soup")

                {
                    Product product = new Product();
                    product.Type   = type;
                    product.Name   = name;
                    product.Weight = weight;
                    product.Price  = price;
                    menuProducts.Add(product);
                }
                else
                {
                    Console.WriteLine("invalid article");
                }
                input = Console.ReadLine().Split(new string[] { ", " }, StringSplitOptions.None).ToArray();
            }
            while (input[0] != "Exit")
            {
                if (input[0] == "Sales")
                {
                    Console.WriteLine($"Tables total count: {orders.Count}");
                    TotalSales(orders);
                    Console.WriteLine("By categories: ");
                    PrintSalad(orders);
                    PrintSoup(orders);
                    PrintMainDish(orders);
                    PrintDesert(orders);
                    PrintDrink(orders);
                    input = Console.ReadLine().Split(new string[] { ", " }, StringSplitOptions.None).ToArray();
                    continue;
                }
                int table = int.Parse(input[0]);
                MakeOrder(table, orders, input, menuProducts);

                input = Console.ReadLine().Split(new string[] { ", " }, StringSplitOptions.None).ToArray();
            }
            Console.WriteLine($"Tables total count: {orders.Count}");
            TotalSales(orders);
            Console.WriteLine("By categories: ");
            PrintSalad(orders);
            PrintSoup(orders);
            PrintMainDish(orders);
            PrintDesert(orders);
            PrintDrink(orders);
        }