Problem Statement
For those who file jointly and have a taxable income of at least $100,000
the tax for 2004 is calculated from the following table. To calculate
your tax, you find
the appropriate bracket for your taxable income, multiply your taxable income by the multiplier,
and then subtract the subtraction value.
At_least Less_than Multiplier Subtraction
100,000 117,250 25% 6,525.00
117,250 178,650 28% 10,042.50
178,650 319,100 33% 18,975.00
319,100 - 35% 25,357.00
When I find out how much tax someone had to pay, I want to be able to figure
out what their taxable income was. Create a class TaxTable that contains a
method income that is given the taxAmount and calculates the taxable income whose
tax is closest to taxAmount. This result is returned,
rounded to the nearest dollar (.5 rounds up). If the
taxAmount is too low to have come from the table, return -1.
Definition
- Class:
- TaxTable
- Method:
- income
- Parameters:
- int
- Returns:
- int
- Method signature:
- int income(int taxAmount)
- (be sure your method is public)
Constraints
- taxAmount will be between 0 and 1,000,000, inclusive.
- All values within 1e-6 of the taxable income corresponding to taxAmount will round to the same integer.
Examples
47025
Returns: 200000
The tax on $200,000 is 33% * 200,000 - 18975 which is 47025.1000
Returns: -1
Anybody who has taxable income of at least $100,000 has a tax that is greater than $100047026
Returns: 200003
The tax on $200,000 is exactly $47,025. For each dollar above that we must pay 33 cents additional tax. So the income that results in a tax of exactly $47,026 is $200,003.0303030303.... which rounds to $200,003. Note that a return of 200002 would be incorrect, even though the tax on that amount would be 47025.66 which is close to 47026.86304
Returns: 319027
22792
Returns: 117266