コード例 #1
0
        public string Receive(string chickenQ, string eggQ, string customerName, string drinkingType, TableRequests tableRequests)
        {
            this.tableRequests = tableRequests;
            if (receiveIndex > 7)
            {
                throw new Exception("Up to 8 customers are allowed per table. Send to Cook first!");
            }
            var   chQ      = Convert.ToInt32(chickenQ);
            var   eQ       = Convert.ToInt32(eggQ);
            Drink drinking = new Pepsi();

            if (drinkingType == "Cola")
            {
                drinking = new Cola();
            }
            if (drinkingType == "Tea")
            {
                drinking = new Tea();
            }
            ServeDrinkings.Add(customerName.ToUpper() + " is served " + drinking.GetType().Name);

            for (int i = 0; i < chQ; i++)
            {
                tableRequests.Add <Chicken>(customerName);
            }
            for (int i = 0; i < eQ; i++)
            {
                tableRequests.Add <Egg>(customerName);
            }
            receiveIndex++;
            return("Request received from: " + customerName.ToUpper());
        }
コード例 #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("1 - Japan");
            Console.WriteLine("2 - Spain");
            Console.WriteLine("3 - US");
            string country;

            for (; ;)
            {
                Console.Write("Choose a Country : ");
                country = Console.ReadLine();
                try {
                    if (Int32.Parse(country) >= 4)
                    {
                        Console.WriteLine("Choose the correct option!!");
                    }
                    else
                    {
                        break;
                    }
                } catch (System.FormatException) {
                    Console.WriteLine("Choose a No. !!");
                }
            }
            Console.WriteLine(country);
            //Japan japan = new Japan(20);

            Coke  coke  = new Coke("Coke", 20, 12.99);
            Pepsi pepsi = new Pepsi("Pepsi", 10, 2.30);

            SodasVendingMachine <IJapanesSoda> jSodaVending = new SodasVendingMachine <IJapanesSoda>(25, "SODA");

            jSodaVending.SodaList.Add(coke);
            jSodaVending.SodaList.Add(pepsi);

            Japan japan = new Japan();

            japan.vendingMachines.Add((VendingMachine <IJapanesSoda>)jSodaVending);
            Console.WriteLine(jSodaVending.Name);
            japan.vendingMachines.ForEach(v => {
                Console.WriteLine($"{v.Name}");
            });
        }