试图弄清楚如何完成这个方法
使用此版本,最终的“税无法解析为变量”
public double calculateTax() {
if (salary < 9440){
double tax = 0;
}
else {
double newSalary = salary - 9440;
if (newSalary <= 32010) {
double tax = newSalary*0.2;
} else {
double tax1 = 32010*0.2;
double tax2 = (newSalary - 32010)*0.4;
double tax = tax1 + tax2;
}
}
return tax;
}
然而,在这个版本中,“方法不返回双精度类型的结果”
public double calculateTax() {
if (salary < 9440){
double tax = 0;
} else {
double newSalary = salary - 9440;
if (newSalary <= 32010) {
double tax = newSalary*0.2;
} else {
double tax1 = 32010*0.2;
double tax2 = (newSalary - 32010)*0.4;
double tax = tax1 + tax2;
return tax;
}
}
}
我不能为这个项目定义一个单独的税收字段——我应该把退税放在哪里?谢谢 :)