Question

In: Computer Science

The purpose of this assignment is to test your familiarity with Java I/O statements and if-else statements.

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
************************************

Solutions

Expert Solution


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
*************************************


Related Solutions

I/O Lab Java Purpose To practice the input and output concepts discussed in this module. Specifically,...
I/O Lab Java Purpose To practice the input and output concepts discussed in this module. Specifically, reading from and writing to local files, and formatting output. Instructions Read in file input.csv and generate a cleanly formatted table in output.txt. See the samples below. input.csv name,ID,salary,years experience foo,1,13890,12 bar,2,2342,3 baz,3,99999,24 output.txt Name | ID | Salary | Years experience -----+----+--------+----------------- Foo | 1 | 13890 | 12 Bar | 2 | 2342 | 3 Baz | 3 | 99999 | 24
Assignment Purpose The purpose of this lab is to write a well commented java program that...
Assignment Purpose The purpose of this lab is to write a well commented java program that demonstrates the use of one dimensional arrays and methods.(Need Comment, Write by Java Code) Instructions Write a method rotateArray that is passed to an array, x, of integers (minimum 7 numbers) and an integer rotation count, n. x is an array filled with randomly generated integers between 1 and 100. The method creates a new array with the items of x moved forward by...
Assignment Purpose The purpose of this lab is to write a well commented java program that...
Assignment Purpose The purpose of this lab is to write a well commented java program that demonstrates the use and re-use of methods with input validation. Instructions It is quite interesting that most of us are likely to be able to read and comprehend words, even if the alphabets of these words are scrambled (two of them) given the fact that the first and last alphabets remain the same. For example, “I dn'ot gvie a dman for a man taht...
Assignment Purpose The purpose of this lab is to write a well commented java program that...
Assignment Purpose The purpose of this lab is to write a well commented java program that demonstrates the use of one dimensional arrays and methods. Instructions Write a method rotateArray that is passed to an array, x, of integers (minimum 7 numbers) and an integer rotation count, n. x is an array filled with randomly generated integers between 1 and 100. The method creates a new array with the items of x moved forward by n Elements that are rotated...
IN JAVA Minimal Documentation Required (no javadoc) Purpose The purpose of this assignment is to introduce...
IN JAVA Minimal Documentation Required (no javadoc) Purpose The purpose of this assignment is to introduce you to basic operations on a linked list. Specifics Design a program that generates a linked list of randomly generated Integer objects. Present a menu at program start that gives the user the following options (most of these options will have corresponding methods in a Linked List class): 1. Create a new list. The size will be specified by the user, make sure a...
Assignment Purpose The purpose of this lab is to write a well commented java program that...
Assignment Purpose The purpose of this lab is to write a well commented java program that demonstrates the use of two dimensional arrays, input validation, and methods. (Write by Java Code, Need Comment) Instructions A theater seating chart is implemented as a two-dimensional array of ticket prices, like this: Seat Ticket Price 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10...
Assignment Purpose The purpose of this lab is to write a well commented java program that...
Assignment Purpose The purpose of this lab is to write a well commented java program that demonstrates the use of one dimensional arrays and methods. Instructions Write a method rotateArray that is passed to an array, x, of integers (minimum 7 numbers) and an integer rotation count, n. x is an array filled with randomly generated integers between 1 and 100. The method creates a new array with the items of x moved forward by n Elements that are rotated...
Assignment Purpose The purpose of this lab is to write a well-commented java program that demonstrates...
Assignment Purpose The purpose of this lab is to write a well-commented java program that demonstrates the use of loops, and generation of random integers. Instructions You are taking some time off from your paint business and currently are on vacation in Bahamas. You decide to write a Java program that generates 10 random numbers between 1 and 20 (all integers). You cannot use arrays (even if you know what they are) to store these numbers. It then picks up...
Assignment Overview This assignment will give you practice with interactive programs and if/else statements. Part 1:...
Assignment Overview This assignment will give you practice with interactive programs and if/else statements. Part 1: User name Generator Write a program that prompts for and reads the user’s first and last name (separately). Then print a string composed of the first letter of the user’s first name, followed by the first five characters of the user’s last name, followed by a random number in the range 10 to 99. Assume that the last name is at least five letters...
This week we really want to learn about a file I/O in Java. In Java: 1)...
This week we really want to learn about a file I/O in Java. In Java: 1) Create a plain empty text file named contacts. 2) Populate the text file with a person's name and account number on each line(Joe Doe 123456789). Create 10 accounts. 3) Store that file in the same location as your project 4) Write a program that will find that file and load it into the computers memory. 5) Read each line of the file and print...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT