Problem Statement
Most countries use a system of individual income tax where the tax rate varies based on the amount of income earned. The United States, for example, uses a progressive tax system where higher income families pay more taxes per dollar than lower income families. Regardless of the system used, it is obvious that having a higher income should still leave an individual better off after taxes than having a lower income (otherwise we would have people trying to make less money in some cases). Also, a person with higher income should pay a total amount greater than or equal to a person with lower income. We ensure this by setting income brackets, described below.
Here is an example of a valid tax system:
- Anyone with income less than or equal to $4500 pays no taxes
- Anyone with income over $4500 and less than or equal to $20,000 pays 15% tax only on THE PORTION OVER $4500
- Anyone with income over $20,000 and less than or equal to $55,000 pays 22% tax on the amount over $20,000 in addition to the income tax households earning $20,000 pay.
- Anyone with income over $55,000 and less than or equal to $120,000 pays 28% tax on the amount over $55,000 in addition to the income tax households earning $55,000 pay.
- Anyone with income over $120,000 pays 40% tax on the amount over $120,000 in addition to the income tax households earning $120,000 pay.
In this example, if you earn $70,000, you are in the second highest income bracket and you must pay 28% of $15,000 (because $70,000 - $15,000 = $55,000), 22% of $35,000 (because $55,000 - $35,000 = $20,000), and 15% of $15,500 (because $20,000 - $15,500 = $4,500). The income brackets in this example are the 15% bracket, the 22% bracket, the 28% bracket, and the 40% bracket (also notice that income less than $4500 is not taxed).
Write a method that takes as inputs an income level, income, a
brackets = {15, 22, 28, 40}
cutoffs = {4500, 20000, 55000, 120000}
income = 70000
Returns: 15000 * (0.28) + 35000 * (0.22) + 15500 * (0.15) = 14225
Definition
- Class:
- Taxes
- Method:
- calcTaxes
- Parameters:
- int[], int[], int
- Returns:
- int
- Method signature:
- int calcTaxes(int[] brackets, int[] cutoffs, int income)
- (be sure your method is public)
Notes
- The elements of brackets might not be increasing (contrary to the tax system in most countries)
- Any amount made greater than the highest cutoff is taxed at the rate specified by the highest bracket.
- Any amount made less than or equal to the lowest cutoff is not taxed.
Constraints
- Elements of brackets must be ints between 0 and 99 inclusive.
- Elements of cutoffs must be increasing (cutoffs[i] > cutoffs[i-1]).
- Elements of cutoffs must be ints between 0 and 10000000 inclusive and divisible by 100
- brackets and cutoffs must contain the same number of elements.
- Income must be an int between 0 and 10000000 inclusive and divisible by 100.
Examples
{15, 22, 28, 40}
{4500, 20000, 55000, 120000}
70000
Returns: 14225
The explanation for this example is in the problem statement.
{15, 22, 28, 40}
{4500, 20000, 55000, 120000}
170000
Returns: 48225
This household earns $100,000 more than the one from the previous example. The additional taxes consist of $50,000 extra taxed at 28% and $50,000 extra taxed at 40%. $14225 + (0.28) * $50,000 + (0.40) * $50,000 = $48225
{5}
{0}
100000
Returns: 5000
This system represents a country with a flat-rate 5% income tax regardless of income.
{50}
{0}
500
Returns: 250
The tax on $500 at a rate of 50% is $250.
{15, 22, 28, 40}
{4500, 20000, 55000, 120000}
4000
Returns: 0
Because the lowest cutoff is $4500, a household earning $4000 pays nothing.
{50,50,50,50,50}
{0,100,200,300,400}
500
Returns: 250
This test is meant to ensure that the rounding is not done until the very end. Update - Changed now that rounding is no longer an issue.
{49}
{0}
100
Returns: 49
{15, 22, 28, 40}
{4500, 20000, 55000, 120000}
55000
Returns: 10025
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,0}
{100,200,300,400,500,600,700,800,900,1000,1100,1200,1300,1400,1500,1600,1700,1800,1900,2000,2100,2200,2300,2400,2500}
10000000
Returns: 300
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,0}
{100,200,300,400,500,600,700,800,900,1000,1100,1200,1300,1400,1500,1600,1700,1800,1900,2000,2100,2200,2300,2400,2500}
9000
Returns: 300
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,1}
{100,200,300,400,500,600,700,800,900,1000,1100,1200,1300,1400,1500,1600,1700,1800,1900,2000,2100,2200,2300,2400}
29700
Returns: 549
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,1}
{100,200,300,400,500,600,700,800,900,1000,1100,1200,1300,1400,1500,1600,1700,1800,1900,2000,2100,2200,2300,2400}
29800
Returns: 550
{0,50,99,45,22,0,3,0,3,71}
{500,1200,4700,6800,9100,111000,130000,1700000,9999000,9999500}
10000000
Returns: 74752
{99,95,92,85,0}
{10000,100000,350000,700000,800000}
9999900
Returns: 733600
{37,71,84,23,37,43}
{1100,5300,7700,9100,14500,27300}
7654300
Returns: 3290022
{1,2,3,4,5,6,7,8,9}
{5000,10000,13000,15500,17900,21200,890900,1111000,2222200}
10000000
Returns: 856933
{ 15 }
{ 4500 }
4500
Returns: 0
{ 10 }
{ 1000 }
100000
Returns: 9900
{ 10, 20, 30, 40 }
{ 5000, 10000, 40000, 60000 }
67000
Returns: 15300
{ 15, 30 }
{ 100, 10000 }
3000
Returns: 435
{ 22 }
{ 50000 }
200
Returns: 0
{ 0, 20, 30, 40, 50 }
{ 400, 500, 600, 800, 900 }
600
Returns: 20
{ 50 }
{ 1000 }
1200
Returns: 100
{ 80 }
{ 10000 }
100000
Returns: 72000
{ 12, 22, 28, 40 }
{ 4500, 20000, 55000, 120000 }
30000
Returns: 4060
{ 15 }
{ 4500 }
4500
Returns: 0
{ 10 }
{ 1000 }
100000
Returns: 9900
{ 10, 20, 30, 40 }
{ 5000, 10000, 40000, 60000 }
67000
Returns: 15300
{ 15, 30 }
{ 100, 10000 }
3000
Returns: 435
{ 22 }
{ 50000 }
200
Returns: 0
{ 0, 20, 30, 40, 50 }
{ 400, 500, 600, 800, 900 }
600
Returns: 20
{ 50 }
{ 1000 }
1200
Returns: 100
{ 80 }
{ 10000 }
100000
Returns: 72000
{ 12, 22, 28, 40 }
{ 4500, 20000, 55000, 120000 }
30000
Returns: 4060