The Question:
Write a program that prompts the user to enter his/her taxable income and then calculates the income tax due using the 2014 tax table below. Express the tax with two decimal places.
Income tax brackets for single-filers
up to $9075 10%
$9076 - $36900 15%
$36901 - $89350 25%
$89351 - $186350 28%
$186351 - $405100 33%
This is what I have so far. I'm really new to Java so keep that in mind. My specific question will come after my code.
import java.util.Scanner;
public class IncomeTax {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
// Prompt the user to enter taxable income
System.out.print("Enter the amount of taxable income for the year 2014: ");
double income = input.nextDouble();
// Compute tax
double tax = 0;
if (income <= 9075)
tax = income * 0.10;
else if (income <= 9076)
tax = 9075 * 0.10 + (income - 36900) * 0.15;
else if (income <= 36901)
tax = 9075 * 0.10 + (9076 - 36900) * 0.15 + (income - 89350) * 0.25;
else if (income <= 89351)
tax = 9075 * 0.10 + (9076 - 36900) * 0.15 + (36901 - 89350) * 0.25 + (income - 186350) + 0.28;
else if (income <= 186351)
tax = 9075 * 0.10 + (9076 - 36900) * 0.15 + (36901 - 89350) * 0.25 + (89351 - 186350) + 0.28 + (income - 405100) + 0.33;
if (income <= 9075)
System.out.println("You have entered the 10% bracket.");
else if (income <= 9076)
System.out.println("You have entered the 15% bracket.");
else if (income <= 36901)
System.out.println("You have entered the 25% bracket.");
else if (income <= 89351)
System.out.println("You have entered the 28% bracket.");
else if (income <= 186351)
System.out.println("You have entered the 33% bracket.");
}
}
The final output should look like this:
Enter the amount of taxable income for the year 2014. (user input here ->) 5000
You have entered the 10% tax bracket.
Your income is $5,000.00, Your tax is: $500.00. Your income after tax is: $4,500.00
How do I get my output to look like the above output? Specifically the decimals and the $ sign.
The output code that I am currently working on is:
System.out.println("Your income is: " + "Your taxx is: " + (int)(tax * 100) / 100.0) + "Your income after tax is: " + ;