Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

SearchLTE 9:49 AM 72%- Back Prg2 - Income Tax.doc Programming Assignment 2: Comp

ID: 3729681 • Letter: S

Question

SearchLTE 9:49 AM 72%- Back Prg2 - Income Tax.doc Programming Assignment 2: Computing Income Tax Problem Description: 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 witha 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. Table 1 2009 U.S. Federal Personal Tax Rates Marginal Tax Rate Single Married Filing Jointly or Qualified Widow(er) Married Filing Separately Head of Household -5835 1-5455 You are to write a 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.

Explanation / Answer

ANS >>>>

i am given here basic java implementaion as follow...

=================================================

java implementaion :-

import java.io.*;

public class javaAssign2 {

   public static void main(String[] args) throws IOException {
       BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

       System.out.println("Enter your filing status.");
       System.out.println("0: Single");
       System.out.println("1: Married filing jointly");
       System.out.println("2: Married filing seperately");
       System.out.println("3: Head of Household");
       int status = Integer.parseInt(br.readLine());

       System.out.print("Enter the taxable income: ");
       double income = Integer.parseInt(br.readLine());
       double tax = 0;
      
       switch (status) {
       case 0: {
           if (income <= 8350)
               tax = income * .10;
           if (income > 8351 && income <= 33950)
               tax = 8350 * 0.10 + (income - 8350) * 0.15;
           if (income > 33950 && income <= 82250)
               tax = 8350 * 0.10 + (33950 - 8350) * 0.15 + (income - 33950)
                       * 0.25;
           if (income > 82250 && income <= 171550)
               tax = 8350 * 0.10 + (33950 - 8350) * 0.15 + (82250 - 33950)
                       * 0.25 + (income - 82250) * 0.28;
           if (income > 171550 && income <= 372950)
               tax = 8350 * 0.10 + (33950 - 8350) * 0.15 + (82250 - 33950)
                       * 0.25 + (171550 - 82250) * 0.28 + (income - 171550)
                       * 0.33;
           if (income > 372950)
               tax = 8350 * 0.10 + (33950 - 8350) * 0.15 + (82250 - 33950)
                       * 0.25 + (171550 - 82250) * 0.28 + (372950 - 171550)
                       * 0.33 + (income - 372950) * 0.35;
           break;
       }
      
               //case 1 is not calculating to the same tax as the test case 1 is.
       case 1: {
           if (income <= 16700)
               tax = income * 0.10;
           if (income > 16700 && income <= 67900)
               tax = 16700 * 0.10 + (income - 16700) * 0.15;
           if (income > 67900 && income <= 137050)
               tax = 16700 * 0.10 + (67900 - 16700) * 0.15 + (income - 67900)
                       * 0.25;
           if (income > 137050 && income <= 208850)
               tax = 16700 * 0.10 + (67900 - 16700) * 0.15 + (137050 - 67900)
                       * 0.25 + (income - 137050) * 0.28;
           if (income > 208850 && income <= 372950)
               tax = 16700 * 0.10 + (67900 - 16700) * 0.15 + (137050 - 67900)
                       * 0.25 + (208850 - 137050) * 0.28 + (income - 208850)
                       * 0.33;
           if (income > 372950)
               tax = 16700 * 0.10 + (67900 - 16700) * 0.15 + (137050 - 67900)
                       * 0.25 + (208850 - 137050) * 0.28 + (372950 - 208850)
                       * 0.33 + (income - 372950) * 0.35;
           break;
       }
      
      
       }
      
       System.out.println("Tax is " + tax);
      
       }
      
   }

==================================================

optimizing above program

import java.io.*;

public class javaAssign2 {

public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

System.out.println("Enter your filing status.");
System.out.println("0: Single");
System.out.println("1: Married filing jointly");
System.out.println("2: Married filing seperately");
System.out.println("3: Head of Household");
int status = Integer.parseInt(br.readLine());

System.out.print("Enter the taxable income: ");
double income = Integer.parseInt(br.readLine());
double tax = 0;

switch (status) {
case 0: {
if (income <= 8350)
tax = income * .10;
if (income > 8351 && income <= 33950)
tax = 8350 * 0.10 + (income - 8350) * 0.15;
if (income > 33950 && income <= 82250)
tax = 8350 * 0.10 + (33950 - 8350) * 0.15 + (income - 33950)
* 0.25;
if (income > 82250 && income <= 171550)
tax = 8350 * 0.10 + (33950 - 8350) * 0.15 + (82250 - 33950)
* 0.25 + (income - 82250) * 0.28;
if (income > 171550 && income <= 372950)
tax = 8350 * 0.10 + (33950 - 8350) * 0.15 + (82250 - 33950)
* 0.25 + (171550 - 82250) * 0.28 + (income - 171550)
* 0.33;
if (income > 372950)
tax = 8350 * 0.10 + (33950 - 8350) * 0.15 + (82250 - 33950)
* 0.25 + (171550 - 82250) * 0.28 + (372950 - 171550)
* 0.33 + (income - 372950) * 0.35;
break;
}

               //case 1 is not calculating to the same tax as the test case 1 is.
case 1: {
if (income <= 16700)
tax = income * 0.10;
if (income > 16700 && income <= 67900)
tax = 16700 * 0.10 + (income - 16700) * 0.15;
if (income > 67900 && income <= 137050)
tax = 16700 * 0.10 + (67900 - 16700) * 0.15 + (income - 67900)
* 0.25;
if (income > 137050 && income <= 208850)
tax = 16700 * 0.10 + (67900 - 16700) * 0.15 + (137050 - 67900)
* 0.25 + (income - 137050) * 0.28;
if (income > 208850 && income <= 372950)
tax = 16700 * 0.10 + (67900 - 16700) * 0.15 + (137050 - 67900)
* 0.25 + (208850 - 137050) * 0.28 + (income - 208850)
* 0.33;
if (income > 372950)
tax = 16700 * 0.10 + (67900 - 16700) * 0.15 + (137050 - 67900)
* 0.25 + (208850 - 137050) * 0.28 + (372950 - 208850)
* 0.33 + (income - 372950) * 0.35;
break;
}


}

System.out.println("Tax is " + tax);

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote