Conditionals


Conditionals

Condition.java

Deitel 4.1-4.7, 5.6, 5.7, 5.9


Classwork


Part A

 ☑ Create a class Taxpayer which has instance variables to store income, age, and marital status.

Part B

We will use the following scheme for taxes:

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 use conditionals to 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 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. (Remember that once they have paid tax on a chunk of money in a higher bracket, they are done paying tax on that money entirely.)

 ☑ Print a final statment like "From an income of $75000.0 you owe $12500.0 tax and your remaining income is $62500.0." (specific numbers will depend on exemptions.).

 ☑ Use an inline conditional in this printout so that if they pay 0 tax it reads something like  "From an income of $9000.0, you owe no tax and your remaining income is $9000.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 for instance if a taxpayer makes 88000 you might print

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 $18590.0 tax and your remaining income is $69410.0

 

 

  [EC + 20]

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!!).  Display the taxed income to the user in the output.

So for instance if a single 30 year old makes 93000 you might print

Your 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 $18590.0 tax and your remaining income is $74410.0