private static void ShoppingCart() { IList <ICheckoutItem> _lstCheckItem = new List <ICheckoutItem>(); IList <IProduct> _lstProduct = new List <IProduct>(); //set up store products _lstProduct = SetupProducts(); //check out items var cart = new CheckoutProcesor(_lstCheckItem, _lstProduct); var item = new CheckoutItem() { CheckoutItemId = 1, ProductId = 1, Quantity = 1 }; cart.AddItem(item); item = new CheckoutItem() { CheckoutItemId = 2, ProductId = 2, Quantity = 1 }; cart.AddItem(item); //get the cost for the checkout items var tot = cart.GetTotalCost(); Console.WriteLine($"Total number of the items checked out and the cost: {cart.GetTotalItems().Count} {tot.ToString("C")}."); }
private static void ShoppingCartWithOffer() { IList <ICheckoutItem> _lstCheckItem = new List <ICheckoutItem>(); IList <IProduct> _lstProduct = new List <IProduct>(); //set up store products _lstProduct = SetupProducts(); //set up offers IList <KeyValuePair <int, OfferFlags> > lstProductOffer; lstProductOffer = new List <KeyValuePair <int, OfferFlags> >() { new KeyValuePair <int, OfferFlags>(1, OfferFlags.BuyOneGetOneFree), new KeyValuePair <int, OfferFlags>(2, OfferFlags.ThreeForTwo) }; //check out items var cart = new CheckoutProcesor(_lstCheckItem, _lstProduct); var item = new CheckoutItem() { CheckoutItemId = 1, ProductId = 1, Quantity = 1 }; cart.AddItem(item); item = new CheckoutItem() { CheckoutItemId = 2, ProductId = 2, Quantity = 1 }; cart.AddItem(item); item = new CheckoutItem() { CheckoutItemId = 3, ProductId = 1, Quantity = 1 }; cart.AddItem(item); //get the cost for the checkout items with the offers var tot = cart.GetTotalCost(lstProductOffer); Console.WriteLine($"Total number of the items checked out with offers and the cost: {cart.GetTotalItems().Count} {tot.ToString("C")}."); }