import java.util.Scanner;
public class Main {
public static void main
(String[] args
) { Scanner reader
= new Scanner
(System.
in); System.
out.
println("Which filing status number suits you? "); System.
out.
println("0. Single filer\n1. Married filing jointly\n2. Married filing seperately\n3. Head of household"); System.
out.
print("Enter the filing status: "); int status
= Integer.
parseInt(reader.
nextLine()); System.
out.
print("Enter the taxable income: "); double income
= Double.
parseDouble(reader.
nextLine()); if (income < 0){
System.
out.
println("Taxable income can not be negative!"); return ;
}
double tax = 0;
if (status == 0) {
tax += addTaxForBracketIfIncomeHighEnough(income, 0, 8350, 0.10);
tax += addTaxForBracketIfIncomeHighEnough(income, 8350, 33950, 0.15);
tax += addTaxForBracketIfIncomeHighEnough(income, 33950, 82250, 0.25);
tax += addTaxForBracketIfIncomeHighEnough(income, 82250, 171500, 0.28);
tax += addTaxForBracketIfIncomeHighEnough(income, 171550, 372950, 0.33);
tax
+= addTaxForBracketIfIncomeHighEnough
(income,
372950,
Double.
MAX_VALUE,
0.35); }
if (status == 1) {
if ( income <= 16700){
tax = income * 0.10;
} else if (income <= 67900) {
tax = (16700 * 0.10) + (income-16700) * 0.15;
} else if (income <= 137050) {
tax = (16700 * 0.10) + ((67900-16700) * 0.15) + ((income-67900) * 0.25);
} else if (income <= 208850) {
tax = (16700 * 0.10) + ((67900-16700) * 0.15) + ((137050-67900) * 0.25) + ((income-137050) * 0.28);
} else if (income <= 372950) {
tax = (16700 * 0.10) + ((67900-16700) * 0.15) + ((137050-67900) * 0.25) + ((208850-137050) * 0.28) + ((income-208850) * 0.33);
} else if ( income >= 372951) {
tax = (16700 * 0.10) + ((67900-16700) * 0.15) + ((137050-67900) * 0.25) + ((208850-137050) * 0.28) + ((372950-208850) * 0.33) + ((income-372950) * 0.35);
}
}
if (status == 2) {
if ( income <= 8350){
tax = income * 0.10;
} else if (income <= 33950) {
tax = (8350 * 0.10) + (income-8350) * 0.15;
} else if (income <= 68525) {
tax = (8350 * 0.10) + ((33950-8350) * 0.15) + ((income-33950) * 0.25);
} else if (income <= 104425) {
tax = (8350 * 0.10) + ((33950-8350) * 0.15) + ((68525-33950) * 0.25) + ((income-68525) * 0.28);
} else if (income <= 186475) {
tax = (8350 * 0.10) + ((33950-8350) * 0.15) + ((68525-33950) * 0.25) + ((104425-68525) * 0.28) + ((income-104425) * 0.33);
} else if ( income >= 186476) {
tax = (8350 * 0.10) + ((33950-8350) * 0.15) + ((68525-33950) * 0.25) + ((104425-68525) * 0.28) + ((186475-104425) * 0.33) + ((income-186475) * 0.35);
}
}
if (status == 3) {
if ( income <= 11950){
tax = income * 0.10;
} else if (income <= 45500) {
tax = (11950 * 0.10) + (income-11950) * 0.15;
} else if (income <= 117450) {
tax = (11950 * 0.10) + ((45500-11950) * 0.15) + ((income-45500) * 0.25);
} else if (income <= 190200) {
tax = (11950 * 0.10) + ((45500-11950) * 0.15) + ((117450-45500) * 0.25) + ((income-117450) * 0.28);
} else if (income <= 372950) {
tax = (11950 * 0.10) + ((45500-11950) * 0.15) + ((117450-45500) * 0.25) + ((190200-117450) * 0.28) + ((income-190200) * 0.33);
} else if ( income >= 372951) {
tax = (11950 * 0.10) + ((45500-11950) * 0.15) + ((117450-45500) * 0.25) + ((190200-117450) * 0.28) + ((372950-190200) * 0.33) + ((income-372950) * 0.35);
}
}
System.
out.
println("Tax is " + tax
); }
private static double addTaxForBracketIfIncomeHighEnough(double income, double lowerLimit, double upperLimit, double percentageOfBracket) {
if (income <= lowerLimit){
return 0;
}
return ((income > upperLimit ? upperLimit : income) - lowerLimit) * percentageOfBracket;
}
}