Write a program called TaxTable that prints out separate tables for different fi
ID: 3761446 • Letter: W
Question
Write a program called TaxTable that prints out separate tables for different filing status (Single, Married Filing Jointly or Qualifying Widow(er), Married Filing Separately, and Head of House). Your program will have a main() method and one other method calledcomputeTax() with the following method header:
This method should compute the tax owed given a tax status number and a given amount of taxable income. You can find the code that computes the tax owed from the ComputeTax.java program from Chapter 3 of the textbook. You can use the code in this class, but it is inside the main() method of this program, and you will have to remove it from there and place it into the computeTax() method of the program that you have to write.
In the main() method of the program you have to write, you will create one or more loops that print the four sets of tax tables for taxable income from $50,000 to $60,000 in intervals of $50. Each tax table represents one of the four filing status. You must print out separate tables for each separate filing status (Single, Married Filing Jointly or Qualifying Widow(er), Married Filing Separately, and Head of House). An abbreviated version of these outputs is shown below:
Explanation / Answer
import java.util.Scanner;
public class Taxtable
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
System.out.print("(0-single filer, 1-married jointly, " +"2-married separately, 3-head of household) " +"Enter the filing status: ");
int status = scanner.nextInt();
System.out.print("Enter the taxable income: ");
double income = scanner.nextDouble();
System.out.println("Tax is " +(int)(computeTax(status, income) * 100) / 100.0);
}
public static double computeTax(int status, double income)
{
double[] rates = {0.10, 0.15, 0.27, 0.30, 0.35, 0.386};
int[][] brackets =
{
//Approximate values
{6000, 27950, 67700, 141250, 307050}, // Single filer
{12000, 46700, 112850, 171950, 307050}, // Married jointly
{6000, 23350, 56425, 85975, 153525}, // Married separately
{10000, 37450, 96700, 156600, 307050} // Head of household
};
double tax = 0;
if (income <= brackets[status][0])
return tax = income * rates[0];
else
tax = brackets[status][0] * rates[0];
for (int i = 1; i < brackets[0].length; i++)
{
if (income > brackets[status][i])
tax += (brackets[status][i] - brackets[status][i - 1]) *rates[i];
else
{
tax += (income - brackets[status][i - 1]) * rates[i];
return tax;
}
}
return tax += (income - brackets[status][4]) * rates[5];
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.