using System.Collections.Generic;
public interface ICheckout
public Item(string sku, int price, int specialPrice = 0, int specialCount = 0)
this.SpecialPrice = specialPrice;
this.SpecialCount = specialCount;
public int getDiscountedPrice(int itemCount)
int individualItems = itemCount;
int specialItemCount = 0;
if (this.SpecialCount > 0)
individualItems = itemCount % this.SpecialCount;
specialItemCount = (itemCount - individualItems) / this.SpecialCount;
return (individualItems * this.Price) + (specialItemCount * this.SpecialPrice);
Console.WriteLine(e.Message);
public class Checkout : ICheckout
public List<Item> ScannedItems;
this.Items = new List<Item>();
this.ScannedItems = new List<Item>();
public void Scan(string item)
if (this.Items == null || this.Items.Count == 0)
for (int i = 0; i < this.Items.Count; i++)
Item currentItem = this.Items[i];
if (currentItem != null && currentItem.Sku == item)
this.ScannedItems.Add(currentItem);
if (this.ScannedItems == null || this.ScannedItems.Count == 0)
List<Item> distinctSkus = this.getDistinctItems();
for (int i = 0; i < distinctSkus.Count; i++)
Item currentItem = distinctSkus[i];
int currentSkuCount = getCountForSku(currentItem.Sku);
totalPrice += currentItem.getDiscountedPrice(currentSkuCount);
public List<Item> getDistinctItems()
List<Item> distinctItems = new List<Item>();
if (this.ScannedItems == null || this.ScannedItems.Count == 0)
for (int i = 0; i < this.ScannedItems.Count; i++)
Item scannedItem = this.ScannedItems[i];
if (!distinctItems.Contains(scannedItem))
distinctItems.Add(scannedItem);
public int getCountForSku(string sku)
if (this.ScannedItems == null || this.ScannedItems.Count == 0)
for (int i = 0; i < this.ScannedItems.Count; i++)
Item scannedItem = this.ScannedItems[i];
if (scannedItem.Sku == sku)
public void addItem(Item item)
Checkout checkout = new Checkout();
checkout.addItem(new Item("A", 50, 130, 3));
checkout.addItem(new Item("B", 30, 45, 2));
checkout.addItem(new Item("C", 20, 0, 0));
checkout.addItem(new Item("D", 15, 0, 0));
Console.WriteLine("Please scan the item");
string Sku = Console.ReadLine();
Console.WriteLine("Press 1 to scan more items or press ...");
decision = Console.ReadLine();
Console.WriteLine("Total Price is -");
Console.WriteLine(checkout.GetTotal());