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.
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 |
10% |
$0 – $8,350 |
$0 – $16,700 |
$0 – $8,350 |
$0 – $11,950 |
15% |
$8,351– $33,950 |
$16,701 – $67,900 |
$8,351 – $33,950 |
$11,951 – $45,500 |
25% |
$33,951 – $82,250 |
$67,901 – $137,050 |
$33,951 – $68,525 |
$45,501 – $117,450 |
28% |
$82,251 – $171,550 |
$137,051 – $208,850 |
$68,525 – $104,425 |
$117,451 – $190,200 |
33% |
$171,551 – $372,950 |
$208,851 – $372,950 |
$104,426 – $186,475 |
$190,201 - $372,950 |
35% |
$372,951+ |
$372,951+ |
$186,476+ |
$372,951+ |
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.
Here are sample runs of the program:
Sample 1:
Enter the filing status: 0
Enter the taxable income: 100000
Tax is 21720.0
Sample 2:
Enter the filing status: 1
Enter the taxable income: 300339
Tax is 76932.87
Sample 3:
Enter the filing status: 2
Enter the taxable income: 123500
Tax is 29665.5
Sample 4:
Enter the filing status: 3
Enter the taxable income: 4545402
Tax is 1565250.7
Analysis: |
(Describe the problem including input and output in your own words.) |
Design: |
(Describe the major steps for solving the problem.) |
JAVA PROGRAM
import java.util.Scanner;
/**
*
* Class: PersonlaIncomeTaxCalculator
*
*/
public class PersonlaIncomeTaxCalculator {
private static final String[] FILLING_STATUS =
{"single filers","married filing jointly","married filing
separately","head of household"};
private static final double[] TAX_RATES =
{0.1,0.15,0.25,0.28,0.33,0.35};
//The below 2D double array is created to hold upper
tax bracket limit for each of tax rates which has upper limit
//0th row of 2d array represents upper tax bracket for
10% tax rate, 1st row represents for 15% tax rate and so on
//Each column of 2d array represent the upper tax
bracket for a particular filling status
//for example TAX_BRACKETS[1][2] will represent: upper
tax bracket limit (33950) of "married filing separately" for 15%
tax rate
//for example TAX_BRACKETS[3][3] will represent: upper
tax bracket limit (190200) of "head of household" for 28% tax
rate
//and so on..
private static final double[][] TAX_BRACKETS = {
{8350,16700,8350,11950}, //upper limit of tax bracket
for 10% tax
{33950,67900,33950,45500},
//upper limit of tax bracket for 15% tax
{82250,137050,68525,117450},//upper limit of tax bracket for 25%
tax
{171550,208850,104425,190200},//upper limit of tax bracket for 28%
tax
{372950,372950,186475,372950}//upper limit of tax bracket for 33%
tax
//no upper limit for 35% tax
rate(hence row for this not added here)
};
//MAIN PROGRAM
public static void main(String[] args){
Scanner sc = new
Scanner(System.in);//user input scanner
System.out.println("Personal Income
Tax Calculator");
System.out.println("===============================");
//print the filling status
for(int i = 0 ; i <
FILLING_STATUS.length ; i++){
System.out.println("Enter "+i+" for "+FILLING_STATUS[i]);
}
int choice = -1;
do{
System.out.println("Enter your choice:");
choice =
sc.nextInt();
if(choice <0
|| choice > 3){
System.out.println("Invalid Input.Please try
again!");
}else{
break;
}
}while(true);//try as long as valid
input is not given
System.out.println("Enter the
taxable income:");
double taxableIncome =
sc.nextDouble();//enter taxable total income
double tax = calculateTax(choice,
taxableIncome);//calculate tax
System.out.println("Tax is:
"+tax);//print tax
}
/**
* Calculate tax based on choice and the taxable
income
* @param choice
* @param taxableIncome
* @return
*/
private static double calculateTax(int choice, double
taxableIncome){
double totalTax = 0;
double currentLowerLimit = 0;
boolean checkAgain = false;
int i = 0;
//loop till last but one tax
rate(33%) (hence i < TAX_RATES.length -1)
//as the last one has no upper
limit
for(i = 0; i <
TAX_RATES.length -1; i++){
double
currentUpperLimit = TAX_BRACKETS[i][choice];//get current upper
limit
double
currentTaxRate = TAX_RATES[i];//get tax rate
double
applicableAmountForCurrentTaxRate = 0;
//calculating
the amount on which current tax rate will be applicable
if(taxableIncome
>= currentUpperLimit){
applicableAmountForCurrentTaxRate =
currentUpperLimit - currentLowerLimit;
checkAgain = true;//as there is some more tax
amount to be taxed at next tax rate
}else{
applicableAmountForCurrentTaxRate =
taxableIncome - currentLowerLimit;
checkAgain = false;//as there is no more tax
amount on which next tax rate can be applied
}
//calculate tax
and add it with previous totalTax
totalTax =
totalTax +
(applicableAmountForCurrentTaxRate*currentTaxRate);
if(checkAgain){//adjust the lower limit
currentLowerLimit = currentUpperLimit;
}else{
//break out of the loop is furthr check is not
needed
break;
}
}
//outside for loop:
//if checkAgain still remains true,
it means check for last tax rate(35%)
//int variable i at this point will
also point to last index of TX_RATES
if(checkAgain){
totalTax =
totalTax + (taxableIncome - currentLowerLimit)* TAX_RATES[i];
}
return totalTax;
}
}
==================================
OUTPUT
==================================
Run1
Personal Income Tax Calculator
===============================
Enter 0 for single filers
Enter 1 for married filing jointly
Enter 2 for married filing separately
Enter 3 for head of household
Enter your choice:
0
Enter the taxable income:
100000
Tax is: 21720.0
Run2
Personal Income Tax Calculator
===============================
Enter 0 for single filers
Enter 1 for married filing jointly
Enter 2 for married filing separately
Enter 3 for head of household
Enter your choice:
1
Enter the taxable income:
300339
Tax is: 76932.87
Run3
Personal Income Tax Calculator
===============================
Enter 0 for single filers
Enter 1 for married filing jointly
Enter 2 for married filing separately
Enter 3 for head of household
Enter your choice:
2
Enter the taxable income:
123500
Tax is: 29665.5
Run4
Personal Income Tax Calculator
===============================
Enter 0 for single filers
Enter 1 for married filing jointly
Enter 2 for married filing separately
Enter 3 for head of household
Enter your choice:
3
Enter the taxable income:
4545402
Tax is: 1565250.7
Get Answers For Free
Most questions answered within 1 hours.