从撒拉和撒拉总税中找到净薪金

时间:2019-10-24 21:07:37

标签: java eclipse

现在我被困在这项任务上:

该方法应采用工资总额,计算税额,减去税额后返回净工资。

税率将适用以下规则:

salary >= 45,000 pays a 50% tax rate, 
       >= 30,000 pays a 30% and 
          everyone else pays 15%.

这是我的代码:

public double salaryTax(double salary) {

    double taxRate=0;

    if (salary >= 45.000) {
         taxRate = .5;

    }
    else if (salary >= 30.000) {
        taxRate = .3;
    }
    else
    {
        taxRate = .15;
    }
    double tax = salary * taxRate;
    double totalTax = tax + taxRate;
    double netSalary = salary - totalTax;
    return  netSalary;
}

但是,当我进行测试时,它与我应该拥有的实际数量相差0.5……

1 个答案:

答案 0 :(得分:0)

尝试一下。希望对您有帮助

public double salaryTax(double salary) {

    double taxRate = 0.15;

    if (salary >= 45000) {
         taxRate = 0.5;

    }
    else if (salary >= 30000) {
        taxRate = 0.3;
    }

    return  salary*(1.0- taxRate);
}