public override List<string> GetPromotionText(LineItem lineItem) {
            List<string> promotionText = new List<string>();

            int remainingQuantity = lineItem.Quantity;
            int setsOfMinimumQuantities = 0;
            int quantityToBeDiscounted = 0;

            while (remainingQuantity >= minNumberItemsForPromotion) {
                remainingQuantity -= minNumberItemsForPromotion;
                setsOfMinimumQuantities++;

                if (remainingQuantity >= quantityEligibleForDiscount) {
                    quantityToBeDiscounted += quantityEligibleForDiscount;
                } else {
                    quantityToBeDiscounted += remainingQuantity;
                }

                remainingQuantity -= quantityEligibleForDiscount;
            }

            if (remainingQuantity < 0) {
                remainingQuantity = 0;
            }

            promotionText.Add("Promotion: " + setsOfMinimumQuantities + " set of " + minNumberItemsForPromotion + " means you get the next " + quantityEligibleForDiscount + " at a discount of " + (discountPercentage * 100) + "% off");

            if (remainingQuantity != 0) {
                promotionText.Add("Remaining: " + remainingQuantity + " @ $" + String.Format("{0:0.00}",lineItem.PricePerUnit) + " each");
            }

            return promotionText;
        }
        public override double GetPromotionAdjustedTotalCost(LineItem lineItem) {
            if (lineItem == null) {
                return 0;
            }

            int remainingQuantity = lineItem.Quantity;
            int setsOfMinimumQuantities = 0;
            int quantityToBeDiscounted = 0;

            while (remainingQuantity >= minNumberItemsForPromotion) {
                remainingQuantity -= minNumberItemsForPromotion;
                setsOfMinimumQuantities++;

                if (remainingQuantity >= quantityEligibleForDiscount) {
                    quantityToBeDiscounted += quantityEligibleForDiscount;
                } else {
                    quantityToBeDiscounted += remainingQuantity;
                }

                remainingQuantity -= quantityEligibleForDiscount;
            }

            if (remainingQuantity < 0) {
                remainingQuantity = 0;
            }

            double costForMinimumSets = (setsOfMinimumQuantities * minNumberItemsForPromotion) * lineItem.PricePerUnit;
            double remainingQuantityCost = remainingQuantity * lineItem.PricePerUnit;
            double discountedCosts = quantityToBeDiscounted * (lineItem.PricePerUnit * discountPercentage);
            return costForMinimumSets + remainingQuantityCost + discountedCosts;
        }
Example #3
0
        public void AddItem(Item item) {
            if (item == null) {
                throw new ArgumentException(ERROR_MSG_ADDING_NULL_ITEM_TO_CART);
            }

            if (lineItems.ContainsKey(item)) {
                lineItems[item].Increment();
            } else {
                LineItem lineItem = new LineItem(item);
                lineItem.Increment();
                lineItems.Add(item, lineItem);
            }
        }
        public override double GetPromotionAdjustedTotalCost(LineItem lineItem) {
            if (lineItem == null) {
                return 0;
            }

            int setsOfMinimumQuantities = lineItem.Quantity / minNumberItemsForPromotion;
            double adjustedPromotionCostForSets = setsOfMinimumQuantities * promotionPrice;

            int remainingQuantity = lineItem.Quantity % minNumberItemsForPromotion;
            double remainingQuantityCost = remainingQuantity * lineItem.PricePerUnit;

            return adjustedPromotionCostForSets + remainingQuantityCost;
        }
        public override List<string> GetPromotionText(LineItem lineItem) {
            List<string> promotionText = new List<string>();

            int setsOfMinimumQuantities = lineItem.Quantity / minNumberItemsForPromotion;
            double adjustedPromotionCostForSets = setsOfMinimumQuantities * promotionPrice;
            int remainingQuantity = lineItem.Quantity % minNumberItemsForPromotion;

            promotionText.Add("Promotion: " + setsOfMinimumQuantities + " set of " + minNumberItemsForPromotion + " @ $" + String.Format("{0:0.00}", promotionPrice) + " each");

            if (remainingQuantity != 0) {
                promotionText.Add("Remaining: " + remainingQuantity + " @ $" + String.Format("{0:0.00}", lineItem.PricePerUnit) + " each");
            }

            return promotionText;
        }
Example #6
0
        public void AddItem(Item item, int quantity) {
            if (item == null) {
                throw new ArgumentException(ERROR_MSG_ADDING_NULL_ITEM_TO_CART);
            }

            if (quantity <= 0) {
                throw new ArgumentException(ERROR_MSG_INVALID_QUANTITY);
            }

            if (DoesCartContainItem(item)) {
                LineItem lineItem = GetLineItemForItem(item);
                lineItem.Quantity = lineItem.Quantity + quantity;
            } else {
                LineItem lineItem = new LineItem(item);
                lineItem.Quantity += quantity;
                lineItems.Add(item, lineItem);
            }
        }
        public override double GetPromotionAdjustedTotalCost(LineItem lineItem) {
            if (lineItem == null) {
                return 0;
            }

            int remainingQuantity = lineItem.Quantity;
            int setsOfMinimumQuantities = 0;

            while (remainingQuantity >= minNumberItemsForPromotion) {
                remainingQuantity = remainingQuantity - minNumberItemsForPromotion;
                setsOfMinimumQuantities++;
                remainingQuantity = remainingQuantity - quantityFree;
            }

            if (remainingQuantity < 0) {
                remainingQuantity = 0;
            }

            double costForMinimumSets = (setsOfMinimumQuantities * minNumberItemsForPromotion) * lineItem.PricePerUnit;
            double remainingQuantityCost = remainingQuantity * lineItem.PricePerUnit;
            return costForMinimumSets + remainingQuantityCost;
        }
        public override List<string> GetPromotionText(LineItem lineItem) {
            List<string> promotionText = new List<string>();

            int remainingQuantity = lineItem.Quantity;
            int setsOfMinimumQuantities = 0;

            while (remainingQuantity >= minNumberItemsForPromotion) {
                remainingQuantity = remainingQuantity - minNumberItemsForPromotion;
                setsOfMinimumQuantities++;
                remainingQuantity = remainingQuantity - quantityFree;
            }

            if (remainingQuantity < 0) {
                remainingQuantity = 0;
            }

            promotionText.Add("Promotion: " + setsOfMinimumQuantities + " set of " + minNumberItemsForPromotion + " means you get " + (setsOfMinimumQuantities * quantityFree) + " free");

            if (remainingQuantity != 0) {
                promotionText.Add("Remaining: " + remainingQuantity + " @ $" + String.Format("{0:0.00}",lineItem.PricePerUnit) + " each");
            }

            return promotionText;
        }
Example #9
0
 abstract public List<string> GetPromotionText(LineItem lineItem);
Example #10
0
 abstract public double GetPromotionAdjustedTotalCost(LineItem lineItem);