Inheritance: Restaurant.Starter
示例#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'));
        }
示例#2
0
        public static void Main(string[] args)
        {
            List <Product> listing = new List <Product>();

            Coffee  coffe  = new Coffee("Lavaza", 30);
            Dessert desert = new Dessert("Nedelq", 25, 500, 1000);
            var     tea    = new Tea("Twings", 2, 250);
            var     soup   = new Soup("Potato", 3, 250);

            listing.Add(coffe);
            listing.Add(desert);
            listing.Add(tea);
            listing.Add(soup);

            foreach (var item in listing)
            {
                System.Console.WriteLine($"{item.GetType()}, {item.Name}, {item.Price},{item}");
            }
        }