...
if (filingStatus == 0) {
//compute tax for single
if (taxableIncome <= 8350) {
tax = taxableIncome * 10 / 100;
} else if (taxableIncome <= 33950) {
tax = (taxableIncome - 8350) * 0.15 + 8350 * 0.10;
} else if (taxableIncome <= 82250) {
tax = 8350 * 0.1 + (33950 - 8350) * 0.15 + (taxableIncome - 33951) * 0.25;
} else if (taxableIncome <= 171550) {
tax = 8350 * 0.1 + (33950 - 8350) * 0.15 + (82250 - 33951) * 0.25 + (taxableIncome - 82251) * 0.28;
} else if (taxableIncome <= 372950) {
tax = 8350 * 0.1 + (33950 - 8350) * 0.15 + (82250 - 33951) * 0.25 + (171550 - 82251) * 0.28 + (taxableIncome - 171551) * 0.33;
} else {
tax = 8350 * 0.1 + (33950 - 8350) * 0.15 + (82250 - 33951) * 0.25 + (171550 - 82251) * 0.28 + (372950 - 171551) * 0.33 + 0.35 * (taxableIncome - 372951);
}
}
System.out.println("tax is " + tax);
}
}
Output
$ javac Egone.java && java Egone.java
Enter taxable income
400000
Enter the filing status 0-single, 1-married filing jointly, 2-married filing separately, 3-head of household
0
tax is 117682.29
if (filingStatus == 0) {
//compute tax for single
if (taxableIncome <= 8350) {
tax = taxableIncome * 10 / 100;
} else if (taxableIncome <= 33950) {
tax = (taxableIncome - 8350) * 15 / 100 + 8350 * 10 / 100;
} else if (taxableIncome <= 82250) {
tax = 8350 * 10 / 100 + (33950 - 8350) * 15 / 100 + (taxableIncome - 33951) * 25 / 100;
} else if (taxableIncome <= 171550) {
tax = 8350 * 10 / 100 + (33950 - 8350) * 15 / 100 + (82250 - 33951) * 25 / 100 + (taxableIncome - 82251) * 28 / 100;
} else if (taxableIncome <= 372950) {
tax = 8350 * 10 / 100 + (33950 - 8350) * 15 / 100 + (82250 - 33951) * 25 / 100 + (171550 - 82251) * 28 / 100 + (taxableIncome - 171551) * 33 / 100;
} else {
tax = 8350 * 10 / 100 + (33950 - 8350) * 15 / 100 + (82250 - 33951) * 25 / 100 + (171550 - 82251) * 28 / 100 + (372950 - 171551) * 33 / 100 + (taxableIncome - 372951) * 35 / 100;
}
}
System.out.println("tax is " + tax);
}
}
Output
$ javac Egone.java && java Egone.java
Enter taxable income
400000
Enter the filing status 0-single, 1-married filing jointly, 2-married filing separately, 3-head of household
0
tax is 117680.15
But this doesn’t work
...
if (filingStatus == 0) {
//compute tax for single
if (taxableIncome <= 8350) {
tax = 10 / 100 * taxableIncome;
} else if (taxableIncome <= 33950) {
tax = 15 / 100 * (taxableIncome - 8350) + 10 / 100 * 8350;
} else if (taxableIncome <= 82250) {
tax = 8350 * 10 / 100 + (33950 - 8350) * 15 / 100 + (taxableIncome - 33951) * 25 / 100;
} else if (taxableIncome <= 171550) {
tax = 10 / 100 * 8350 + 15 / 100 * (33950 - 8350) + 25 / 100 * (82250 - 33951) + 28 / 100 * (taxableIncome - 82251);
} else if (taxableIncome <= 372950) {
tax = 10 / 100 * 8350 + 15 / 100 * (33950 - 8350) + 25 / 100 * (82250 - 33951) + 28 / 100 * (171550 - 82251) + 33 / 100 * (taxableIncome - 171551);
} else {
tax = 10 / 100 * 8350 + 15 / 100 * (33950 - 8350) + 25 / 100 * (82250 - 33951) + 28 / 100 * (171550 - 82251) + 33 / 100 * (372950 - 171551) + 35 / 100 * (taxableIncome - 372951);
}
}
System.out.println("tax is " + tax);
}
}
This is producing wrong results, why?