CS 163/164, Summer 2018
Programming Assignment - P4
Tax Computation
Due Monday, Jun. 25th at 6:00 pm
Late Tuesday, Jun. 26th at 8:00 am
Objectives of this Assignment
- To teach you to read input from the keyboard,
- to see if you can figure out an algorithm,
- to learn how to use conditionals (if/else if/else) statements,
- to print formatted output, and
- to understand how progressive taxation works!
Description
The program allows the user to input some of the information that normally appears on
a tax form, then it calculates a tax bill according to the formulas described below.
WARNING: Be aware that the tax computation shown here is greatly simplified and
should not be used for calculation of your real taxes!
Instructions
For this assignment, you must follow directions exactly. Create a P4 project in Eclipse
then write a class P4 with a main method, and put all of the following code into the main method:
- Instantiate a single Scanner object to read console input.
- Declare doubles for the gross salary, interest income, and capital gains.
- Declare an integer for the number of exemptions.
- Declare doubles for the total income, adjusted income, federal tax, and state tax.
- Print the prompt shown below and ask the user for their gross salary.
- The gross salary represents dollars, which can be entered with or without decimal points.
- Print the prompt shown below and ask the user for the number of exemptions.
- The number of exemptions is an integer.
- Print the prompt shown below and ask the user for their interest income.
- The interest income represents dollars, which can be entered with or without decimal points.
- Print the prompt shown below and ask the user for their capital gains income.
- The capital gains represents dollars, which can be entered with or without decimal points.
- Perform the calculation of federal total income, as shown in the Formula section.
- Perform the calculation of the federal adjusted income, as shown in the Formula section.
- Perform the calculation of the federal total tax, as shown in the Formula section.
- Perform the calculation of the state income tax, as shown in the Formula section.
- Print out the total income, adjusted income, total tax, and state tax.
- You may use integer or floating point for the computations.
- The output should always report exactly 2 digits after the decimal, so use System.out.printf.
- Your program should be accurate to within $0.01.
- Use variables to store everything, don't try to do all the calculation in a print statement!
- Do not hard code values, we will test your program with different values.
- You do not need to handle a negative adjusted income.
- The example below shows four lines of user input (in blue font), with prompts, followed by
four lines of program output (in black font).
Salary: 92768.54
Exemptions: 8
Interest: 1234.50
Gains: 4400.99
Total Income: $93404.03
Adjusted Income: $84404.03
Total Tax: $15033.13
State Tax: $5486.26
Formulas
HINT: A helpful visual aid for the math portion is here.
- Total Income = Gross Salary + Interest Income + Capital Gains - $5000.00
- if (Number of Exemptions > 6) Number of Exemptions = 6
- Adjusted Income = Total Income - (Number of Exemptions * 1500.00)
Total Tax computation:
- 0% on Adjusted Income greater than equal to $0 and less than $20,000 +
- 13% on Adjusted Income greater than equal to $20,000 and up to $35,000 +
- 23% on Adjusted Income greater than equal to $35,000 and up to $50,000 +
- 28% of Adjusted Income greater than equal to $50,000
For the example above, we compute the Total Tax in the example above as follows:
13% * (35,000.00-20,000.00) = 1,950.00
23% * (50,000.00-35,000.00) = 3,450.00
28% * (84,404.03-50,000.00) = 9,633.13
Adding up the above we get a Total Tax of $15,033.13. That's a chunk of change!
You can see the results of our other computations in output shown above.
State Tax = Adjusted Income * 6.5%
Specifications
- Work on your own, as always.
- The name of the source code file must be exactly
P4.java
- Name the file exactly - upper and lower case matters!
- Comments at the top as shown above.
- Assignments should be implemented using Eclipse.
- Assignments should be implemented using Java, version 1.8.
- Make sure your code runs on machines in the CSB 120 lab.
- Turn in through the Checkin tab.
- Read the syllabus for the late policy.
- We will be checking programs for plagiarism, so please don't copy from anyone else.
Grading Criteria
- 100 points for perfect submission.
- 0 points for no submission, will not compile, submitted class file, etc.
- Preliminary Tests use the input data shown in the example output above.
- compileTest: checks that program compiles. (0 points)
- test1: checks gross salary prompt and input. (5 points)
- test2: checks number of exemptions prompt and input. (5 points)
- test3: checks interest income prompt and input. (5 points)
- test4: checks capital gains prompt and input. (5 points)
- test5: checks output of total income, including label. (10 points)
- test6: checks output of adjusted income, including label. (10 points)
- test7: checks output of total tax, including label. (10 points)
- test8: checks output of state tax, including label. (10 points)
- Final Tests use arbitrary input data selected by us!
- test9: checks output of total income, using different inputs. (10 points)
- test10: checks output of adjusted income, using different inputs. (10 points)
- test11: checks output of total tax, using different inputs. (10 points)
- test12: checks output of state tax, using different inputs. (10 points)
- Final grading includes the preliminary tests.
Submit P4.java to the Checkin tab.