Пример #1
0
        private static void Main(string[] args)
        {
            PaymentStrategy paymentStrategy1 = new CashStrategy();
            PaymentStrategy paymentStrategy2 = new CheckStrategy();
            PaymentStrategy paymentStrategy3 = new DebitCardStrategy();

            paymentStrategy1.Pay(100);
            paymentStrategy2.Pay(150);
            paymentStrategy3.Pay(300);

            Console.ReadKey();
        }
        private static void Main(string[] args)
        {
            var customer = new Customer("Cristian", 123456, new DebitCardStrategy());

            customer.Pay(100);

            customer.PaymentStrategy = new CashStrategy();
            customer.Pay(300);

            IPaymentStrategy paymentStrategy = new CashStrategy();

            paymentStrategy.Pay(20);

            Console.ReadKey();
        }
Пример #3
0
        public CashContext(CashStrategy strategy)
        {
            switch (strategy)
            {
            case CashStrategy.Normal:
                _strategy = new CashNormal();
                break;

            case CashStrategy.Return:
                _strategy = new CashReturn();
                break;

            case CashStrategy.Rebate:
                _strategy = new CashRebate();
                break;
            }
        }
Пример #4
0
        static void Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;

            List <Tshirt> selection = new List <Tshirt>
            {
                new Tshirt(Color.Blue, Size.XS, Fabric.Cashmere),
                new Tshirt(Color.Indigo, Size.XXXL, Fabric.Polyester),
                new Tshirt(Color.Violet, Size.XL, Fabric.Silk),
                new Tshirt(Color.Yellow, Size.L, Fabric.Cotton),
                new Tshirt(Color.Green, Size.XXL, Fabric.Wool),
                new Tshirt(Color.Blue, Size.M, Fabric.Cashmere),
                new Tshirt(Color.Green, Size.S, Fabric.Polyester),
                new Tshirt(Color.Orange, Size.XXL, Fabric.Linen),
                new Tshirt(Color.Violet, Size.XS, Fabric.Cotton),
                new Tshirt(Color.Red, Size.S, Fabric.Wool),
                new Tshirt(Color.Yellow, Size.L, Fabric.Rayon),
                new Tshirt(Color.Indigo, Size.XL, Fabric.Polyester),
                new Tshirt(Color.Red, Size.M, Fabric.Silk),
                new Tshirt(Color.Yellow, Size.XL, Fabric.Cotton),
            };

            Console.WriteLine("Look at our beautiful selection. Pick one.");
            int i = 0;

            foreach (var item in selection)
            {
                i++;
                Console.WriteLine(i + ") " + item.Size + " " + item.Color + " T-shirt made from " + item.Fabric);
            }

            string selected    = "";
            int    selectednum = 0;

            do
            {
                selected = Console.ReadLine();
                if (int.TryParse(selected, out selectednum))
                {
                    continue;
                }
            } while (selectednum <= 0 || selectednum > selection.Count);

            Tshirt tshirt = selection[selectednum - 1];

            IPaymentStrategy paymentMethod;

            Console.WriteLine("What payment method do you want?\n1)Credit Card\n2)Bank Transfer\n3)Cash");
            string answer = Console.ReadLine();

            if (answer.Equals("1"))
            {
                paymentMethod = new CreditCardStrategy();
            }
            else if (answer.Equals("2"))
            {
                paymentMethod = new BankTranserStrategy();
            }
            else if (answer.Equals("3"))
            {
                paymentMethod = new CashStrategy();
            }
            else
            {
                paymentMethod = null;
            }

            if (paymentMethod == null)
            {
                Console.WriteLine("Guess you dont want ur tshirt then");
            }
            else
            {
                tshirt.SetPayment(paymentMethod);
                paymentMethod.Payment(tshirt);
            }
        }