using System.Collections.Generic;
public static void Main()
var register = new Register();
register.Feed(new Book("Robinson Crusoe",4.56M));
register.Feed(new Book("Robinson Crusoe",4.56M));
register.Feed(new Food("Imported dog food",6.52M,TaxModificationPercent.Import));
register.Feed(new Other("Perfume",6.23M));
public enum TaxModificationPercent
private List<Product> products = new List<Product>();
public void Feed(Product product)
this.products.Add(product);
foreach(var nameGroup in this.products.GroupBy( p => p.Name ))
decimal item = nameGroup.Sum( p => p.Price );
StringBuilder lineItem = new StringBuilder();
.Append(string.Format("{0:C}",item));
if( nameGroup.Count() > 1 )
.Append(nameGroup.Count())
.Append(string.Format("{0:C}",nameGroup.First().Price))
Console.WriteLine(lineItem.ToString());
decimal tax = this.products.Sum( p => p.Price*p.Tax );
Console.WriteLine("Sales Taxes: " + string.Format("{0:C}",tax));
Console.WriteLine("Total: " + string.Format("{0:C}",total));
public class Book : Product
public Book(string Name, decimal Price) : base(Name, Price){}
public Book(string Name, decimal Price,TaxModificationPercent taxMod)
: base (Name, Price, taxMod){}
public class Food : Product
public Food(string Name, decimal Price) : base(Name, Price){}
public Food(string Name, decimal Price,TaxModificationPercent taxMod)
: base (Name, Price, taxMod){}
public class Medical : Product
public Medical(string Name, decimal Price) : base(Name, Price){}
public Medical(string Name, decimal Price,TaxModificationPercent taxMod)
: base (Name, Price, taxMod){}
public class Other : Product
private decimal _tax = 0.1M;
public override decimal Tax
protected set { _tax = value; }
public Other(string Name, decimal Price) : base(Name, Price){}
public Other(string Name, decimal Price,TaxModificationPercent taxMod)
: base (Name, Price, taxMod){}
public abstract class Product
public decimal Price { get; protected set; }
public string Name { get; protected set; }
protected decimal _Tax = 0;
public virtual decimal Tax
protected set { _Tax = value; }
public Product(string Name, decimal Price)
public Product(string Name, decimal Price, TaxModificationPercent taxMod) : this(Name,Price)
this.Tax += (decimal)taxMod/100;