예제 #1
0
        //Questions for you, Teacher, and also to myself: Is it ok for the CalculateCost method to exist here?
        //Where would you place it as a "best practise"?
        //How can this method be written in order to DRY? With a foreach, perhaps? If so, how could i bring all the variations in a list?

        //Calculating the total cost of a T-shirt

        private static decimal CalculateCost(TShirt tshirt)
        {
            VariationCost variationTotalCost;

            Console.WriteLine();

            //Three VariationTotalCosts following different strategies
            //Note : Shop customer-servise's view:

            Console.WriteLine($"Cost before any variation is : { tshirt.Price }");

            variationTotalCost = new VariationCost(new FabricVariation());
            variationTotalCost.CalculateCostVariation(tshirt);
            Console.WriteLine("Cost after the {1} variation is : {0:c}", tshirt.Price, tshirt.Fabric.GetType().Name);

            variationTotalCost = new VariationCost(new SizeVariation());
            variationTotalCost.CalculateCostVariation(tshirt);
            Console.WriteLine("Cost after the  {1} variation is : {0:c}", tshirt.Price, tshirt.Fabric.GetType().Name);

            variationTotalCost = new VariationCost(new ColorVariation());
            variationTotalCost.CalculateCostVariation(tshirt);
            Console.WriteLine("Cost after the  {1} variation is : {0:c}", tshirt.Price, tshirt.Fabric.GetType().Name);
            Console.WriteLine();
            Console.WriteLine();

            return(tshirt.Price);
        }
예제 #2
0
        public static void EShopInterface()
        {
            Console.WriteLine("Welcome to the T-Shirt E-shop");

            TShirt           tshirt     = CreateTShirt();
            List <Variation> variations = new List <Variation>();
            ColorVariation   c          = new ColorVariation();
            SizeVariation    s          = new SizeVariation();
            FabricVariation  f          = new FabricVariation();

            variations.Add(c);
            variations.Add(s);
            variations.Add(f);

            var basket = new EShopBasket();

            basket.SetVariations(variations);
            basket.CalculatePrice(tshirt);
            basket.SetDueAmount(tshirt.Price);

            Console.Write("How would you like to pay? 1) CreditCard, 2) Bank Transfer, 3) Cash: ");
            var paymentType = int.Parse(Console.ReadLine().Trim());

            var  payments = new Payments();
            bool success  = payments.PayBasket(basket, paymentType);

            Console.WriteLine(success);
            Console.Read();
        }
예제 #3
0
        public static void EshopDemo()
        {
            List <Variation> variations = new List <Variation>()
            {
                new ColorVariation(),
                new SizeVariation(),
                new FabricVariation()
            };

            Console.WriteLine("Hello,What tshirt color u want?");
            var colorInput = Console.ReadLine().Trim().ToUpper();
            var color      = SetColor(colorInput);

            Console.WriteLine("How about Size?");
            var sizeInput = Console.ReadLine().Trim().ToUpper();
            var size      = SetSize(sizeInput);

            Console.WriteLine("Material?");
            var fabricInput = Console.ReadLine().Trim().ToUpper();
            var fabric      = SetFabric(fabricInput);

            Console.WriteLine("Choose Payment Method 1) Credit Card 2) Cash 3) Bank Transfer");
            var paymentInput = Convert.ToInt32(Console.ReadLine().Trim());
            var tShirt       = new TShirt(color, size, fabric);
            var eshop        = new Eshop();

            eshop.SetVariationStrategy(variations);
            eshop.SelectPaymentMethod(paymentInput);
            eshop.PayTShirt(tShirt);
        }
예제 #4
0
        //Print tshirt message on the console

        private static void ShowCustomerTshirtVariationDetails(TShirt sampleTshirt)
        {
            Console.WriteLine();
            Console.WriteLine("Hello, you have chosen this beautiful t-shirt. Its details are : ");
            Console.WriteLine("Fabric : {0} , Size : {1}, Color : {2}", sampleTshirt.Fabric.ToString().ToLower(), sampleTshirt.Size.ToString(), sampleTshirt.Color.ToString().ToLower());
            Console.WriteLine();
        }
예제 #5
0
 public void CalculatePrice(TShirt tshirt)
 {
     foreach (var variation in _variations)
     {
         Console.WriteLine($"Applying {variation.GetType().Name}");
         variation.Cost(tshirt);
         Console.WriteLine($"TShirt cost after applying {variation.GetType().Name} is: {tshirt.Price}");
     }
 }
예제 #6
0
 public void PayTShirt(TShirt tshirt)
 {
     foreach (var variation in _variations)
     {
         Console.WriteLine($"Applying {variation.GetType().Name}");
         variation.Cost(tshirt);
         Console.WriteLine($"TShirt cost after applying {variation.GetType().Name} is: {tshirt.Price}");
     }
     _paymentMethod.Pay(tshirt.Price);
 }
        public void PayTShirt(TShirt tshirt)
        {
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("\n\n\nT-SHIRT PAYMENT PROGRESS");
            Console.ForegroundColor = ConsoleColor.White;
            foreach (var variation in _variations)
            {
                Console.WriteLine($"\nApplying {variation.GetType().Name}");
                variation.Cost(tshirt);
                Console.WriteLine($"TShirt cost after applying {variation.GetType().Name} is: {tshirt.Price}$ ");
            }


            _paymentMethod.Pay(tshirt.Price);
        }
예제 #8
0
        //Letting the user know about the tshirt details

        public static decimal CommunicateWithCustomerAboutTshirt()
        {
            // Suppose a customer added a T-shirt to his wish list

            TShirt sampleTshirt = new TShirt(Color.BLUE, Size.L, Fabric.CASHMERE);

            ShowCustomerTshirtVariationDetails(sampleTshirt);

            //calculate the price of the tshirt

            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.Write("An authorized user sees these details: ");
            var amount = TotalTshirtCost.CalculateCost(sampleTshirt);

            Console.ForegroundColor = ConsoleColor.White;

            return(amount);
        }
예제 #9
0
        public override decimal Cost(TShirt tshirt)
        {
            switch (tshirt.Color)
            {
            case Color.BLUE:
                tshirt.Price += 0.5m;
                break;

            case Color.GREEN:
                tshirt.Price += 0.75m;
                break;

            default:
                tshirt.Price += 1.05m;
                break;
            }

            return(tshirt.Price);
        }
예제 #10
0
        private static int Partition(TShirt[] tShirts, int low, int high, Func <TShirt, TShirt, bool> IsSwappable)
        {
            TShirt pivot = tShirts[high];
            int    i     = (low - 1);

            for (int j = low; j < high; j++)
            {
                if (IsSwappable(pivot, tShirts[j]))
                {
                    i++;
                    TShirt temp = tShirts[i];
                    tShirts[i] = tShirts[j];
                    tShirts[j] = temp;
                }
            }
            TShirt temp1 = tShirts[i + 1];

            tShirts[i + 1] = tShirts[high];
            tShirts[high]  = temp1;
            return(i + 1);
        }
예제 #11
0
        public override decimal Cost(TShirt tshirt)
        {
            switch (tshirt.Color)
            {
            case Color.BLUE:
                tshirt.Price += 0.5m;
                break;

            case Color.GREEN:
                tshirt.Price += 0.75m;
                break;

            case Color.INDIGO:
                tshirt.Price += 1m;
                break;

            case Color.ORANGE:
                tshirt.Price += 1.25m;
                break;

            case Color.RED:
                tshirt.Price += 1.5m;
                break;

            case Color.VIOLET:
                tshirt.Price += 1.75m;
                break;

            case Color.YELLOW:
                tshirt.Price += 2m;
                break;

            default:
                tshirt.Price += 0m;
                break;
            }

            return(tshirt.Price);
        }
예제 #12
0
        public static TShirt CreateTShirt()
        {
            Console.WriteLine("Please choose the color of your t-shirt out of the following options");
            var colors  = Enum.GetValues(typeof(Color));
            int counter = 0;

            foreach (var color in colors)
            {
                Console.WriteLine("{0}      -{1}", ++counter, color);
            }
            Color tshirtColor = (Color)int.Parse(Console.ReadLine().Trim());

            Console.WriteLine("Please choose the size of your t-shirt out of the following options");
            var sizes = Enum.GetValues(typeof(Size));

            counter = 0;
            foreach (var size in sizes)
            {
                Console.WriteLine("{0}      -{1}", ++counter, size);
            }
            Size tshirtSize = (Size)int.Parse(Console.ReadLine().Trim());

            Console.WriteLine("Please choose the fabric of your t-shirt out of the following options");
            var fabrics = Enum.GetValues(typeof(Fabric));

            counter = 0;
            foreach (var fabric in fabrics)
            {
                Console.WriteLine("{0}      -{1}", ++counter, fabric);
            }
            Fabric tshirtFabric = (Fabric)int.Parse(Console.ReadLine().Trim());

            TShirt tshirt = new TShirt(tshirtColor, tshirtSize, tshirtFabric);

            return(tshirt);
        }
예제 #13
0
 public override decimal Cost(TShirt tshirt)
 {
     tshirt.Price += _sizeCosts[tshirt.Size];
     return(tshirt.Price);
 }
예제 #14
0
 public abstract decimal Cost(TShirt item);
예제 #15
0
        // Calculates the variation cost

        public void CalculateCostVariation(TShirt tshirt)
        {
            _variation.Cost(tshirt);
        }
 public override decimal Cost(TShirt tshirt)
 {
     tshirt.Price += _colorVariations[tshirt.Color];
     return(tshirt.Price);
 }
예제 #17
0
 public override decimal Cost(TShirt tshirt)
 {
     tshirt.Price += _fabricVariations[tshirt.Fabric];
     return(tshirt.Price);
 }
예제 #18
0
 public abstract decimal Cost(TShirt tshirt);