Ejemplo n.º 1
0
        public double GetPrice()
        {
            double price = 0;

            price += Dessert?.GetPrice() ?? 0;
            price += Drink?.GetPrice() ?? 0;
            price += Salad?.GetPrice() ?? 0;
            return(price);
        }
Ejemplo n.º 2
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'));
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            Food fish = new Fish("bass", 6.50m);

            Console.WriteLine($"{fish.Name} -> {fish.Price}$ -> {fish.Grams}gr.");
            Dessert souffle = new Cake("souffle");

            Console.WriteLine($"{souffle.Name} -> {souffle.Price}$ -> {souffle.Grams}gr. -> {souffle.Calories}");
            Dessert garash = new Dessert("garash", 8.70m, 70, 280);

            Console.WriteLine($"{garash.Name} -> {garash.Price}$ -> {garash.Grams}gr. -> {garash.Calories}");
        }
Ejemplo n.º 4
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}");
            }
        }