Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Created September 24, 2011 10:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/9cbe9ab68f75f52eebfb to your computer and use it in GitHub Desktop.
Save anonymous/9cbe9ab68f75f52eebfb to your computer and use it in GitHub Desktop.
Tax calculator
public class TaxRate
{
public TaxRate(decimal vat, decimal limit)
{
Vat = vat;
Limit = limit;
}
public decimal Vat { get; private set; }
public decimal Limit { get; private set; }
}
public class TaxCalculator
{
private static IList<TaxRate> taxRates;
static TaxCalculator()
{
taxRates = new List<TaxRate>()
{
new TaxRate(10,0),
new TaxRate(14,5070),
new TaxRate(23,8660),
new TaxRate(30,14070),
new TaxRate(33,21240),
new TaxRate(45,40230)
};
}
public Decimal GetTaxAmount(decimal income)
{
decimal taxToPay = 0;
decimal upperLimit;
TaxRate currentRate;
if (income<=0)
return taxToPay;
upperLimit = income;
for (int i=(taxRates.Count-1); i>-1; i--)
{
currentRate = taxRates[i];
if (income < currentRate.Limit)
continue;
taxToPay += CalculatePercentage(upperLimit - currentRate.Limit, currentRate.Vat);
upperLimit = currentRate.Limit;
}
return taxToPay;
}
private decimal CalculatePercentage(decimal number, decimal percentage)
{
return (number*percentage)/100;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment