In: Computer Science
Objective
The purpose of this assignment is to test your familiarity with Java I/O statements and
if-else statements. This assignment also tests your understanding of the basics of Java
programming and execution, like top-down control flows, translating the logical solution
to a problem into code, and integrating the new concepts you just learned with the
older concepts, including data types and variables, declaration, initialization and
assignments, arithmetic operators, etc.
Please submit your source code (i.e. your java file) on Canvas under HW1.
Problem
It’s the year 2030 and H&R Block is facing a software crisis! Tax season is coming up in a few
months, and their current tax solution is not compatible with the new rules that the IRS has
imposed. They have hired you as a software engineer to program their new system. Your task is
to calculate the income tax a person owes to the IRS. To do so you can use the following table
Tax Bracket Annual Income Tax Owed to the IRS
1 Under $10,000 $0
2 $10,000 - $24,999 15 % of the annual
income
3 $25,000 - $74,999 $3,750 + 20% of the
amount exceeding
$25,000
4 $75,000 - $149,999 $15,000 + 25% of the
amount exceeding
$75,000
5 $150,000 - $299,999 $37,500 + 30% of the
amount exceeding
$150,000
6 Above $300,000 $45,000 + 35% of the
amount exceeding
$300,000
Your program should take as input, the annual income of a user and print the tax bracket and
total tax owed to the IRS. You may round your answers to 2 decimal places.
Sample Run 1
Please enter your annual income ($): $66700
*************************************
Your tax bracket is 3
Total taxes owed to the IRS: $12090.00
************************************
Sample Run 2
Please enter your annual income ($): $16200
*************************************
Your tax bracket is 2
Total taxes owed to the IRS: $2430.00
************************************
Extra Credit (10 points)
Please note, if you are going to attempt this, make sure you submit a version of your original
solution (without the extra credit part) as well.
You should modify your code, to compute / take into account 2 things.
1. Each individual is allowed to claim a standard deduction of upto $12,000, on top of the
annual income he/she earns. You can assume the user will always want to claim this tax
break.
2. You should compute and output the tax refund the user will get in 2030. To do this you
must also input the amount of taxes the user has already paid to the IRS along with
his/her annual income. Then you may calculate the refund by subtracting the taxes
owed to the IRS from the taxes paid to the IRS. If the taxes owed is greater than the
taxes paid, then the program should inform the user that he/she owes money to the
IRS.
Sample Run 3 (this includes the standard deduction computation)
Please enter your annual income ($): 216200
Please enter your taxes paid to the IRS: 82345
*************************************
Your tax bracket is 5
Total taxes owed to the IRS: $53760
Your tax refund is: $28585
************************************
Sample Run 4 (this includes the standard deduction computation)
Please enter your annual income ($): 216200
Please enter your taxes paid to the IRS: 22345
*************************************
Your tax bracket is 5
Total taxes owed to the IRS: $53760
You owe money to the IRS: $31415
************************************
Given below is the code for the question.
To indent code in eclipse , select code by pressing ctrl+a and then
indent using ctrl+i
Please do rate the answer if it was helpful. Thank you
import java.util.Scanner;
public class TaxCalculator {
public static void main(String[] args) {
double DEDUCTION_ALLOWED = 12000;
double income, taxPaid, taxOwed = 0;
double tax = 0;
int taxBracket = 0;
Scanner keyboard = new Scanner(System.in);
System.out.print("Please enter your annual income ($): ");
income = keyboard.nextDouble();
System.out.print("Please enter your taxes paid to the IRS:
");
taxPaid = keyboard.nextDouble();
//remove standard deduction
income -= DEDUCTION_ALLOWED;
if(income < 0)
income = 0;
if(income < 10000){
tax = 0;
taxBracket = 1;
}
else if(income < 25000){
tax = income * 0.15;
taxBracket = 2;
}
else if(income < 75000){
tax = 3750 + (income-25000) * 0.20;
taxBracket = 3;
}
else if(income < 150000){
tax = 15000 + (income-75000) * 0.25;
taxBracket = 4;
}
else if(income < 300000){
tax = 37500 + (income-150000) * 0.30;
taxBracket = 5;
}
else {
tax = 45000 + (income-300000) * 0.35;
taxBracket = 6;
}
taxOwed = tax - taxPaid;
System.out.println("*************************************");
System.out.println("Your tax bracket is " + taxBracket);
System.out.printf("Total taxes owed to the IRS: $%.2f\n",
tax);
if(taxOwed < 0)
System.out.printf("Your tax refund is: $%.2f\n", -taxOwed);
else
System.out.printf("You owe money to the IRS: $%.2f\n",
taxOwed);
System.out.println("*************************************");
}
}
output
-----
Please enter your annual income ($): 216200
Please enter your taxes paid to the IRS: 82345
*************************************
Your tax bracket is 5
Total taxes owed to the IRS: $53760.00
Your tax refund is: $28585.00
*************************************
-----
Please enter your annual income ($): 216200
Please enter your taxes paid to the IRS: 22345
*************************************
Your tax bracket is 5
Total taxes owed to the IRS: $53760.00
You owe money to the IRS: $31415.00
*************************************