1 回答

TA贡献1799条经验 获得超6个赞
你的代码看起来没问题。试试这个,看看是否有效。没有任何变化;我刚刚初始化了一些变量:
public void single() {
double singleLimit = 32000.0; // making it double because your income is in double
double tax1 = 0.0, tax2 = 0.0, totalTax = 0.0; // declaring all tax variables as local variables
income = Double.parseDouble(JOptionPane.showInputDialog("Enter your income ($)"));
if (income <= singleLimit) {
tax1 = rate1 * income;
} else {
tax1 = rate1 * singleLimit;
tax2 = rate2 * (income - singleLimit);
}
double totalTax = tax1 + tax2;
JOptionPane.showMessageDialog(null, "Taxable income for a single person wil be $" + totalTax );
}
添加回答
举报