Created
September 23, 2011 11:53
-
-
Save Linkgoron/1237185 to your computer and use it in GitHub Desktop.
Ayende tax problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class TaxBracket | |
| { | |
| public decimal Minimum { get; set; } | |
| public decimal Percent { get; set; } | |
| public TaxBracket(decimal taxWindow, decimal percent) | |
| { | |
| Minimum = taxWindow; | |
| Percent = percent; | |
| } | |
| } | |
| class Taxing | |
| { | |
| private readonly IEnumerable<TaxBracket> _taxRates = new[] | |
| { | |
| new TaxBracket(40230m, .45m), | |
| new TaxBracket(21240m, .33m), | |
| new TaxBracket(14070m, .30m), | |
| new TaxBracket(8660m, .23m), | |
| new TaxBracket(5070m, .14m), | |
| new TaxBracket(0,.1m), | |
| }; | |
| public decimal GetTaxAmount(decimal salary) | |
| { | |
| var taxSum = 0m; | |
| foreach (var taxBracket in _taxRates.SkipWhile(x => salary < x.Minimum)) | |
| { | |
| var taxedPart = salary - taxBracket.Minimum; | |
| taxSum += taxedPart * taxBracket.Percent; | |
| salary = salary - taxedPart; | |
| } | |
| return taxSum; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment