0

我的 CalcPay 方法没有正确计算加班时间,任何人都可以看到任何会导致这种情况的明显问题吗?

    private const double FED_TAX = 0.2;
    private const int FULL_TIME = 40;
    private const double OVER_TIME = 1.5;
    private const double STATE_TAX = 0.075;


    public double CalcPay()
    {

        double pay = hoursWorked * hourlyWage;
        double overTimeHors = hoursWorked - FULL_TIME;

        if (overTimeHours > 0)
        {
            pay = overTimeHors * (hourlyWage * OVER_TIME);
        }
        double tax1 = pay * FED_TAX;
        double tax2 = pay * STATE_TAX;
        return ((pay - tax1) - tax2);
    }
4

2 回答 2

2

您需要将加班费添加到主工资中,而不是替换它:

if (overTime > 0)
{
    pay += overTime * (hourlyWage * OVER_TIME);
     // ^ increment
}
于 2012-12-08T17:21:49.353 回答
1

问题是您重新定义了可变工资,这意味着您的计算是基于加班费...

于 2012-12-08T17:34:15.103 回答