Taxpayer Project


Part A

Create a class Taxpayer which has instance variables to store

(Think about types and what to call these so it is easy to remember what they mean.)

Include at least a default constructor and a parameterized constructor that takes parameters for all four instance variables, and chain them together. In your mutators, use conditionals to make sure income and age are within valid ranges (yes, babies may pay taxes).

Set up your toString so that output shows age and income.  For married and veteran status, show whichever are true in parens after the rest of the values, or if both are false, add nothing, so we might see output like

age: 42, income: $87000 (married)
age:7, income: $2200 
age: 37, income: $22000 (veteran)
age 89, income $65000 (married, veteran)

Part B

☑ We will figure out how much tax the taxpayer should pay

Here is the overall scheme (please note this is NOT an accurate depiction of US taxes)

 

So a married person who made $91000 would first take out $8000 in exemptions and their taxed income would be 83000. This puts them in the 25% bracket so they would owe 20750

 

Provide a method reportTax() that prints tax information about the Taxpayer something like
taxpayer age: 30, income: $91000.0 (married, veteran) had $83000.0 taxable which was taxed at 0.25% so paid $20750.0 leaving $70250.0
taxpayer age: 70, income: $31000.0 had $25000.0 taxable which was taxed at 0.15% so paid $3750.0 leaving $27250.0

(note that the toString's result is being included in this)

Break down the process of getting these results into at least two other methods (which reportTax can call).  (It is fine to have reportTax call a method that calls another method that calls another...)

You want each method to have a single task to do.  If the task for a method seems very complicated, see if you can break it down into smaller, simpler methods.  For each method, think about what parameters they need to have passed in and what they should return.  You probably want at least a method that returns the total amount of exemptions and a method that returns the total amount of tax.

Do not mess up your instance variables while doing this work -- i.e. don't change the income! 

Don't add any extra instance variables.  If you need to get information from one method to another, pass it as a parameter or return it!

For each method, remember that you can test it individually from your main to check that each piece works individually, instead of trying to get the whole thing working at the same time.


Part C

  ☑ Add to Taxpayer another method higherTax which takes as parameter another Taxpayer and returns whichever Taxpayer pays more tax.  So if we called taxpayer1.higherTax(taxpayer2) it would return either taxpayer1 or taxpayer2, depending on which one had a higher total tax, ignoring the case where they are exactly the same.  (hint, use the methods you already wrote).

  In a separate class with a main, add a method setupTaxPayer which reads in information about a Taxpayers from the user. 

Loop until they give you a non-negative age and income, and either "yes" or "no" when you ask for married and veteran status (separate loops for each will work best).  If they are under 18, don't even ask if they are married or a veteran. 

Create and return the Taxpayer the user described.

 In main, use setupTaxPayer to read in info about 5 TaxPayers from the user.  As each one is created,  report their tax situation.  At the end, report which one pays most tax.  You do not need to store all 5 to do this, only the one with the highest taxes seen so far (hint, when you've only read in the first, who has the highest taxes so far?)


EC +30

To make this look a little more like real taxes, people should pay no tax on the money they make up to $10000, 15% on the amount over $10000 up to $35000, %25 on the amount over $35000 up to $85000, etc.

So someone making $75000 would pay
      0%* 10000
+ %15 * 25000  // amount between 10000 and 35000
+ 25% * 40000. // amount over 35000

Add a method bracketedTax in Taxpayer that calculates the amount of tax to be paid based on this scheme (DO NOT get rid of your existing methods).  When you report the tax paid, in the method you wrote previously, report it under both schemes.