The Problem is :
The United States federal personal income tax is calculated based on filing status and taxable
income. There are four filing statuses: single filers, married filing jointly, married filing separately,
and head of household. The tax rates vary every year. Table 3.2 shows the rates for
2009. If you are, say, single with a taxable income of $10,000, the first $8,350 is taxed at 10%
and the other $1,650 is taxed at 15%. So, your tax is $1,082.5
You are to write a java program to compute personal income tax. Your program should prompt
the user to enter the filing status and taxable income and compute the tax. Enter 0 for single
filers, 1 for married filing jointly, 2 for married filing separately, and 3 for head of household.
Your program computes the tax for the taxable income based on the filing status. The filing
status can be determined using if statements outlined as follows:
if (status == 0) {
// Compute tax for single filers
}
else if (status == 1) {
// Compute tax for married filing jointly
}
else if (status == 2) {
// Compute tax for married filing separately
}
else if (status == 3) {
// Compute tax for head of household
}
else {
// Display wrong status
}
For each filing status there are six tax rates. Each rate is applied to a certain amount of taxable
income. For example, of a taxable income of $400,000 for single filers, $8,350 is taxed at
10%, (33,950 - 8,3502) at 15%, (82,250 - 33,950), at 25%(171,550 - 82,250) at 28%, (372,950 - 171,550) at 33%, (400,000 - 372,950)and at 35%.
The Code I did is incomplete,My ques is : what I did for single filers..should i have to do it again for ramining three types of filers?
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package assignment3tanhaislam; import javax.swing.JOptionPane; /** * * @author Trisa */ public class Assignment3TanhaIslam { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner input = newScanner(System.in); promt int status = input.nextint(); PromtIncome int status = input.nextint(); // Prompt the user to enter filing status String statusString = JOptionPane.showInputDialog( "Enter the filing status:\n" + "(0-single filer, 1-married jointly,\n" + "2-married separately, 3-head of household)"); int status = input.nextInt(); // Prompt the user to enter taxable income String incomeString = JOptionPane.showInputDialog( "Enter the taxable income:"); double income = input.nextDouble(); // Compute tax if(status==0) { // Compute tax for single filers if (income <= 8350) tax = income * 0.10; else if (income <= 33950) tax = 8350 * 0.10 + (income - 8350) * 0.15; else if (income <= 82250) tax = 8350 * 0.10 + (33950 - 8350) * 0.15 + (income - 33950) * 0.25; else if (income <= 171550) tax = 8350 * 0.10 + (33950 - 8350) * 0.15 + (82250 - 33950) * 0.25 + (income - 82250) * 0.28; else if (income <= 372950) tax = 8350 * 0.10 + (33950 - 8350) * 0.15 + (82250 - 33950) * 0.25 + (171550 - 82250) * 0.28 + (income - 171550) * 0.33; else tax = 8350 * 0.10 + (33950 - 8350) * 0.15 + (82250 - 33950) * 0.25 + (171550 - 82250) * 0.28 + (372950 - 171550) * 0.33 + (income - 372950) * 0.35; } else if(status==1) { // Compute tax for married file jointly // Left as exercise } else if (status == 2) { // Compute tax for married separately // Left as exercise } else if (status==3) { // Compute tax for head of household // Left as exercise } else { System.out.println("Error: invalid status"); } // Display the result JOptionPane.showMessageDialog(null, "Tax is " + (int)(tax * 100) / 100.0); } }