Write a Java class TaxCalculator which: 1. Prompts the user to enter inputs for
ID: 3666370 • Letter: W
Question
Write a Java class TaxCalculator which:
1. Prompts the user to enter inputs for a taxpayer’s filing status (char values ‘s’ for single, ‘m’ for married filing married, and ‘f’ for married filing single) and adjusted gross income (double value >= 0) and then scans those inputs; make sure valid values are input, end program if not;
The idea of a ‘marginal’ tax rate is that the income between the limits given (square bracket inclusive, parenthesis not) is taxed at that percent. For example, a single person with gross income 58,000 is taxed at 0% on first 10,000, 8% on 10,000, 12% on 30,000, and 17% on the remaining 8000 between 50 and 58,000;
3. Use a switch statement to choose between different filing statuses, and if/else statements to deal with different gross income amounts;
4. Before printing, round the tax to the nearest whole dollar. Also be sure to be sure to use appropriately named variables throughout.
Table of Tax Rates in % of Adjusted Gross Income Adjusted Gross Income in $K (100, 200]> 200 [0, 10] (10, 20](20,50](50, 100] 25 25 25 25 15 12 10 20 17 15 10 Filing Status 20Explanation / Answer
Program:
// import the required packages
import java.io.*;
import java.util.Scanner;
// class for tax calculation
public class TaxCalculator
{
// main method
public static void main(String[] args)
{
// scanner to read user input
Scanner uin = new Scanner(System.in);
// declare the required variables
Double GrossIncome=0.0;
Double taxIncome,amt;
Double tax_amount;
char sts;
// loop code for continues iteration
do
{
tax_amount=0.0;
// display and get user option
System.out.println("Enter taxpayer's filing status ( 's' for single' 'm' for married, 'f' for married filing single ");
sts = uin.next().charAt(0);
// switch case for tax calculation based on user input filling status
switch(sts)
{
// Tax calculation for single
case 's':
case 'S':
System.out.println("Enter Gross Income");
GrossIncome = uin.nextDouble();
taxIncome= GrossIncome;
if (taxIncome > 10000 && taxIncome <= 20000)
tax_amount = (taxIncome - 10000) * 0.08;
else if (taxIncome > 20000 && taxIncome <= 50000)
tax_amount = 10000 * 0.08 +(taxIncome - 20000) * 0.12;
else if (taxIncome > 50000 && taxIncome <= 100000)
tax_amount = 10000 * 0.08 + 30000 * 0.12+(taxIncome - 50000)*0.17;
else if (taxIncome > 100000 && taxIncome <= 200000)
tax_amount = 10000 * 0.08 + 30000 * 0.12+ 50000*0.17+(taxIncome - 100000)*0.22;
else if (taxIncome > 200000)
tax_amount = 10000 * 0.08 + 30000 * 0.12+ 50000*0.17+ 100000*0.22+(taxIncome - 200000)*0.25;
System.out.println("The Tax amount for the gross income "+GrossIncome+" is " + tax_amount);
break;
// Tax calculation for married
case 'm':
case 'M':
System.out.println("Enter Gross Income");
GrossIncome = uin.nextDouble();
taxIncome= GrossIncome;
if (taxIncome > 10000 && taxIncome <= 20000)
tax_amount = (taxIncome - 10000) * 0.05;
else if (taxIncome > 20000 && taxIncome <= 50000)
tax_amount = 10000 * 0.05 +(taxIncome - 20000) * 0.10;
else if (taxIncome > 50000 && taxIncome <= 100000)
tax_amount = 10000 * 0.05 + 30000 * 0.10+(taxIncome - 50000)*0.15;
else if (taxIncome > 100000 && taxIncome <= 200000)
tax_amount = 10000 * 0.05 + 30000 * 0.10+ 50000*0.15+(taxIncome - 100000)*0.20;
else if (taxIncome > 200000)
tax_amount = 10000 * 0.05 + 30000 * 0.10+ 50000*0.15+ 100000*0.20+(taxIncome - 200000)*0.25;
System.out.println("The Tax amount for the gross income "+GrossIncome+" is " + tax_amount);
break;
// Tax calculation for married but filed as single
case 'f':
case 'F':
System.out.println("Enter Gross Income");
GrossIncome = uin.nextDouble();
taxIncome= GrossIncome;
if (taxIncome > 10000 && taxIncome <= 20000)
tax_amount = (taxIncome - 10000) * 0.10;
else if (taxIncome > 20000 && taxIncome <= 50000)
tax_amount = 10000 * 0.10 +(taxIncome - 20000) * 0.15;
else if (taxIncome > 50000 && taxIncome <= 100000)
tax_amount = 10000 * 0.10 + 30000 * 0.15+(taxIncome - 50000)*0.20;
else if (taxIncome > 100000 && taxIncome <= 200000)
tax_amount = 10000 * 0.10 + 30000 * 0.15+ 50000*0.20+(taxIncome - 100000)*0.25;
else if (taxIncome > 200000)
tax_amount = 10000 * 0.10 + 30000 * 0.15+ 50000*0.20+100000*0.25+(taxIncome - 200000)*0.25;
System.out.println("The Tax amount for the gross income "+GrossIncome+" is " + tax_amount);
break;
default:
System.out.println("Invalid filing status input");
System.exit(0);
}
}while (GrossIncome !=0) ;
}
}
Result:
Enter taxpayer's filing status (
's' for single'
'm' for married,
'f' for married filing single
s
Enter Gross Income
58000
The Tax amount for the gross income 58000.0 is 5760.0
Enter taxpayer's filing status (
's' for single'
'm' for married,
'f' for married filing single
s
Enter Gross Income
200001
The Tax amount for the gross income 200001.0 is 34900.25
Enter taxpayer's filing status (
's' for single'
'm' for married,
'f' for married filing single
s
Enter Gross Income
200000
The Tax amount for the gross income 200000.0 is 34900.0
Enter taxpayer's filing status (
's' for single'
'm' for married,
'f' for married filing single
e
Invalid filing status input
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.