using System.Collections.Generic;
public static void Main()
Console.WriteLine("Please add the product details.");
Basket basket = new Basket();
Boolean _continue = true;
Console.WriteLine("Enter product Name");
var productCode = Console.ReadLine();
Console.WriteLine("Enter product category A or B or C");
var itemType = Console.ReadLine();
Console.WriteLine("Enter product quantity");
int productQuantity = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter product price");
int price = Convert.ToInt32(Console.ReadLine());
basket.AddItem(productCode, itemType.ToString(), productQuantity, price);
Console.WriteLine("Do you want to add more products? Y/ N");
_continue = Console.ReadLine().ToUpper() == "Y";
Console.WriteLine(string.Format("Total payable amount including tax:{0}", basket.GoodsTotal));
public Product(string name, decimal price, Catgory category)
public Catgory CategoryType
public List<BasketItem> BasketItems
BasketItems = new List<BasketItem>();
public decimal GoodsTotal
return BasketItems.Sum(x => x.LineTotal);
public void AddItem(string productCode, string itemType, int quantity, decimal price)
var basketItem = GetItem(productCode, itemType, quantity, price);
BasketItems.Add(basketItem);
private BasketItem GetItem(string productCode, string itemType, int quantity, decimal price)
if (itemType.ToUpper() == "A")
catgory = new CategoryA();
else if (itemType.ToUpper() == "B")
catgory = new CategoryB();
else if (itemType.ToUpper() == "C")
catgory = new CategoryC();
var product = new Product(productCode, price, catgory);
return new BasketItem(quantity, product);
public BasketItem(int quantity, Product product)
return (Price * (Product.CategoryType.TaxPercentage / 100));
return ItemTax * Quantity;
return ((Quantity * Price) + TaxTotal);
public class CategoryA : Catgory
private const decimal _TaxPercentage = 10M;
private const decimal _Price = 100M;
private const string _ItemType = "CategoryA";
public CategoryA(): base (_TaxPercentage, _ItemType)
public class CategoryB : Catgory
private const decimal _TaxPercentage = 20M;
private const string _ItemType = "CategoryB";
public CategoryB(): base (_TaxPercentage, _ItemType)
public class CategoryC : Catgory
private const decimal _TaxPercentage = 0M;
private const string _ItemType = "CategoryC";
public CategoryC(): base (_TaxPercentage, _ItemType)
public Catgory(decimal taxPercentage, string catgeoryType)
TaxPercentage = taxPercentage;
CategoryType = catgeoryType;
public decimal TaxPercentage
public string CategoryType