Conditionals
Deitel 4.1-4.7, 5.6, 5.7, 5.9
☑ Ensure that these cannot be set to unreasonable values.
☑ In the toString, use an inline condition to determine whether a taxpayer is shown to be married, so that we might get results like
a taxpayer (37) making 87000.0
or
a married taxpayer (23) making 122000.0
So if a taxpayer has $75000 taxable income, they would pay 25% on the amount over 35000, which is 40000, 15% on the amount between 10000 and 35000, which is 25000, and 0% on the remaining 10000. So: 0%* 10000 + %15 * 25000 + 25% * 40000 is their total tax.
☑ To your Taxpayer class add a method printTax(). In this method determine tax paid by the Taxpayer as follows:
(You may break this process up into multiple methods if you already feel comfortable doing so.)
Do not lose the values of your instance variables in the process of doing calculations! Do not add extra instance variables!
☑ First use if and else to determine which is the highest tax bracket they must pay in and use an int (or char or String) to record this.
☑ Then use a switch statement on this value and take advantage of falling through multiple cases to actually compute the amount of tax, telling the user how much of their money was in each bracket and how much tax they paid for that bracket as they go.
You had $3000.0 in the 28% bracket, on which you paid $840.0 You had $50000.0 in the 25% bracket, on which you paid $12500.0 You had $25000.0 in the 15% bracket, on which you paid $3750.0 You had $10000.0 in the 0% bracket, on which you paid $0.0 From an income of $88000.0 you owe $17090.0 tax and your remaining income is $70910.0
☑ In a separate main program, create several Taxpayer objects with different values for their instance variables, and for each use printTax to show their tax situation.
So if a single 30 year old makes 80000 the exemption would mean they have $75000 taxable income, on which they would pay 25% on the amount over 35000, which is 40000, 15% on the amount between 10000 and 35000, which is 25000, and 0% on the remaining 10000. So: 0%* 10000 + %15 * 25000 + 25% * 40000 is their total tax.
☑ In printTax, first determine how much of the income is taxed by subtracting out any exemptions that apply (remember not to break your instance vars!!). Only use the taxed income when determining brackets and taxes. Display the taxed income to the user in the output.
So for instance if a single 30 year old makes 93000 you might printYour taxed income: $88000.0 You had $3000.0 in the 28% bracket, on which you paid $840.0 You had $50000.0 in the 25% bracket, on which you paid $12500.0 You had $25000.0 in the 15% bracket, on which you paid $3750.0 You had $10000.0 in the 0% bracket, on which you paid $0.0 From an income of $93000.0 you owe $17090.0 tax and your remaining income is $75910.0