public override double calculate_savings(Dictionary <string, CheckOutItem> availableItems) { //No savings if item is not in store if (!availableItems.ContainsKey(strItemName)) { return(0.0); } double savings = 0.0; CheckOutItem item = availableItems[strItemName]; double dAmountOfItem = get_limited_amount(item.dAmount); //while having enough of item to satisfy criteria while (dAmountOfItem >= dCriteria_Amount) { dAmountOfItem -= dCriteria_Amount; //if can take full advantage of discount if (dAmountOfItem >= dDiscount_item_amount) { dAmountOfItem -= dDiscount_item_amount; savings += (dDiscount_item_amount * item.dCost * dDiscount_amount); } //if only taking partial advantage of discount else { savings += (dAmountOfItem * item.dCost * dDiscount_amount); dAmountOfItem -= dAmountOfItem; } } return(savings); }
public override double calculate_savings(Dictionary <string, CheckOutItem> availableItems) { double savings = 0.0; CheckOutItem itemN = availableItems[strItemName_N]; CheckOutItem itemM = availableItems[strItemName_M]; double nItemNTotalValue = itemN.dCost * nBuyAmount_N; dLimit = nItemNTotalValue / itemM.dCost; double amountOfItem = get_limited_amount(itemM.dAmount); savings += (amountOfItem * itemM.dCost * nDiscount_X); return(savings); }
public void ScanItem(string strItemName, double dAmount = 1) { if (CartItems.ContainsKey(strItemName)) { //Increment number of items CartItems[strItemName].dAmount += dAmount; } else { if (AvailableItems.ContainsKey(strItemName)) { //Add first item to cart CheckOutItem checkOutItem = new CheckOutItem(strItemName, dAmount, AvailableItems[strItemName]); CartItems.Add(strItemName, checkOutItem); } else { throw new System.ArgumentException("Invalid Scan - Item not in system", strItemName); } } }
public override double calculate_savings(Dictionary <string, CheckOutItem> availableItems) { //No savings if item is not in store if (!availableItems.ContainsKey(strItemName)) { return(0.0); } double savings = 0.0; CheckOutItem item = availableItems[strItemName]; double dAmountOfItem = get_limited_amount(item.dAmount); while (dAmountOfItem >= nBuyAmount) { dAmountOfItem -= nBuyAmount; savings += ((nBuyAmount * item.dCost) - dSpecialCost); } return(savings); }