コード例 #1
0
        public Order CalculateDiscount(Order order)
        {
            //your implementation here
            order.Promotion = this.promotion;

            return order;
        }
コード例 #2
0
        public double calculatePrice(Order order)
        {
            Double result = 0;
            OrderItem prevOrderItem = null;
            order.SortBySku();
            foreach (var orderItem in order.Items)
            {
                double perItemPrice = orderItem.Product.Price;

                if (orderItem.Quantity % 2 == 0)
                {
                    result += orderItem.Quantity * orderItem.Product.Price * 0.85; // Applying Discount 2

                }
                else
                {
                    double itemPrice = perItemPrice;
                    // IF there is an odd number in current order and a previous order, check if the item is able to satisfy Discount3, apply discount to the odd number in this
                    if (prevOrderItem != null && SKU.isSameStyle(orderItem.Product.Sku, prevOrderItem.Product.Sku))
                    {
                        itemPrice = 0.5 * itemPrice; // Applying Discount 3
                        prevOrderItem = null;
                    }
                    else
                    {
                        prevOrderItem = orderItem; // Store the previous item for considering the next item if it is not already discounted.
                    }
                    result += ( (orderItem.Quantity - 1) * orderItem.Product.Price * 0.85) + itemPrice;
                    Console.WriteLine("result");
                }

            }
            return result;
        }
コード例 #3
0
ファイル: SampleTest.cs プロジェクト: JANSI-CCN/PromotionCS
        public Order GetOrder()
        {
            Order o = new Order();
            o.Add(Products.GetProduct("blueDress"), 1);
            o.Add(Products.GetProduct("redDress"), 1);
            o.Add(Products.GetProduct("greenDress"), 1);
            o.Add(Products.GetProduct("whiteSocks"), 1);
            o.Add(Products.GetProduct("redSocks"), 1);

            return o;
        }
コード例 #4
0
        public Order CalculateDiscount(Order order)
        {
            for (int i=0; i < order.Items.Count; i++ )
            {
                if (i==1)
                {
                    order.Items[i].Product.Price = order.Items[i].Product.Price * discountRate;
                }
            }

                return order;
        }
コード例 #5
0
ファイル: DiscountTest.cs プロジェクト: JANSI-CCN/PromotionCS
        public void Test1ABuy1Item()
        {
            //setup
            Promotion promo = new Promotion(); //TODO: setup the promotion as you see fit
            DiscountCalculator dc = new DiscountCalculator(promo);

            Order order = new Order(); //TODO: setup the order, you can refer to SampleTest.cs for example

            //exercise
            Order newOrder = dc.CalculateDiscount(order);

            //verify
            double expectedValue = 0;//TODO: set the expected value;
            Assert.AreEqual(expectedValue, newOrder.TotalPrice, 0.001);
            //TODO: add additional verification if necessary
        }
コード例 #6
0
ファイル: DiscountTest.cs プロジェクト: JANSI-CCN/PromotionCS
        public void Test1BBuy2Item()
        {
            //setup
            Promotion promo = new Promotion(); //TODO: setup the promotion as you see fit
            promo.setPromo(0.7);
            DiscountCalculator dc = new DiscountCalculator(promo);

            Order order = new Order(); //TODO: setup the order, you can refer to SampleTest.cs for example
            order.Add(Products.GetProduct("blueDress"), 1);
            order.Add(Products.GetProduct("redDress"), 1);

            //exercise
            Order newOrder = dc.CalculateDiscount(order);

            //verify
            double expectedValue = 170;//TODO: set the expected value;
            Assert.AreEqual(expectedValue, newOrder.TotalPrice, 0.001);
            //TODO: add additional verification if necessary
        }
コード例 #7
0
 public double calculatePrice(Order order)
 {
     Double result = 0;
     foreach (var orderItems in order.getItemByStyle().Values)
     {
         foreach (OrderItem orderItem in orderItems)
         {
             if (orderItems.Count <= 1 && orderItem.Quantity <= 1)
             {
                 result += orderItem.Product.Price * 0.9; // 10% off for 1 item of a style
             }
             else
             {
                 result += orderItem.Quantity * orderItem.Product.Price * 0.8; // 20% for 2 or more item of same style.
             }
         }
     }
     return result;
 }
コード例 #8
0
 public double calculatePrice(Order order)
 {
     Double result = 0;
     foreach (var orderItem in order.Items)
     {
         if (orderItem.Product is WomansInvisibleSocks)
         {
             int quantityNotInBundle = orderItem.Quantity % 3;
             // Adding the quantity not qualify for bundle deal
             result +=  quantityNotInBundle * orderItem.Product.Price;
             // Adding the quantity in bundle deal
             result += ((orderItem.Quantity - quantityNotInBundle) / 3) * 25;
         }
         else
         {
             result += orderItem.Product.Price * orderItem.Quantity;
         }
     }
     return result;
 }
コード例 #9
0
        public void Test1ABuy3Item()
        {
            //setup
            Promotion promo = new PromotionOne(); //TODO: setup the promotion as you see fit
            DiscountCalculator dc = new DiscountCalculator(promo);

            Order o = new Order();
            o.Add(Products.GetProduct("blueDress"), 3);
            //o.Add(Products.GetProduct("redDress"), 3);
            //o.Add(Products.GetProduct("greenDress"), 3);
            //o.Add(Products.GetProduct("whiteSocks"), 3);
            //o.Add(Products.GetProduct("redSocks"), 3);

            //exercise
            Order newOrder = dc.CalculateDiscount(o);

            //verify
            double expectedValue = 100 + +170;

            Assert.AreEqual(expectedValue, newOrder.TotalPrice, 0.001);
            //TODO: add additional verification if necessary
        }