CS 160, Spring 2015
Programming Assignment P4
Programming due Monday, Feb. 16 at 6:00pm; late deadline Feb. 16 at 11:59pm.
A Program for Computing Taxes
This programming assignment has five objectives:
- to teach you to read input from the keyboard,
- to use Java expressions involving integers and real numbers,
- to use conditional (if/else) statements in Java,
- to print formatted output,
- to see if you can figure out an algorithm!
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!
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.
- 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.
- The example below shows four lines of user input (in blue font), with prompts, followed by
four lines of program output.
Gross Salary: 73685.73
Number of Exemptions: 5
Interest Income: 1087.89
Capital Gains: 12682.50
Total Income: $87456.12
Adjusted Income: $78456.12
Total Tax: $16541.84
State Tax: $4315.09
Total Income = Gross Salary + Interest Income + Capital Gains
Adjusted Income = Total Income - (Number of Exemptions * 1800.00)
Total Tax computation:
For the example above, we compute the Total Tax in the example above as follows:
- 0% on Adjusted Income above $0 and up to $12,000, inclusive +
- 12% on Adjusted Income above $12,000 and up to $26,000, inclusive +
- 23% on Adjusted Income above $26,000 and up to $38,500, inclusive +
- 30% of Adjusted Income above $38,500
12% * (26,000.00-12,000.00) = 1,680.00
23% * (38,500.00-26,000.00) = 2,875.00
30% * (78,456.12-38,500.00) = 11,986.84
Adding up the above we get a Total Tax of $16,541.84. That's a chunk of change!
You can see the results of our other computations in output shown above.
State Tax = Adjusted Income * 5.5%
Your program must meet the following specifications:
- 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.
- 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!
- Don't forget the comment block at the top of the program.
- Assignments should be implemented using Eclipse.
- Assignments should be implemented using Java 1.5 or 1.6 or 1.7.
- Make sure your code runs on machines in the COMCS 120 lab.
- Submit your program to the Checkin tab as you were shown in the recitation.
- Read the syllabus for the late policy.
- We will be checking programs for plagiarism, so please don't copy from anyone else.
Submit your program to the Checkin tab on the course website, as you were shown in
the recitation, and read the syllabus for the late policy (if necessary).
- 100 points for perfect submission.
- 0 points for no submission, will not compile, submitted class file, etc.
- Preliminary Tests
- compileTest: checks that program compiles. (20 points)
- test1: checks prompt for gross salary. (5 points)
- test2: checks prompt for number of exemptions. (5 points)
- test3: checks prompt for interest income. (5 points)
- test4: checks prompt for capital gains. (5 points)
- test5: checks output of total income, including label. (10 points)
- test6: checks output of adjusted income, including label. (10 points)
- Final Tests
- test7: checks label on output of total tax. (4 points)
- test8: checks output of total tax, using the income shown. (8 points)
- test9: checks output of total tax, using another income. (8 points)
- test10: checks label on output of state tax. (4 points)
- test11: checks output of state tax, using the income shown. (8 points)
- test12: checks output of state tax, using another income. (8 points)
- Preliminary testing does not check total or state tax, but you should do this manually!
- Final grading includes the preliminary tests.
© 2015 CS160 Colorado State University. All Rights Reserved.