gpt4 book ai didi

java - 快到了,只需要通过工资计算朝着正确的方向稍微插入一下?

转载 作者:行者123 更新时间:2023-12-01 23:10:54 24 4
gpt4 key购买 nike

需要帮助计算两种不同工资标准的工资!错误是净总数不正确。感谢您的所有评论,它们非常有帮助,现在它可以工作了:)我希望我的代码的这一部分可以帮助其他初学者学习使用循环和 if 语句:

public static void main(String[]args)
{
Scanner input = new Scanner (System.in);
DecimalFormat Currency = new DecimalFormat("###,###,##0.00");

double normHrs = 0, overHrs = 0, bonusHrs = 0, actualHrs = 0, normPay = 0, overPay =0, bonusPay = 0, grossWage = 0,vat23 = 0, netWage =0;
String empName, nextEMP = "y";



System.out.println ("************************");
System.out.println ("HUMAN RESOURCES: PAYROLL"); //
System.out.println ("************************");


while (nextEMP.equalsIgnoreCase("y"))
{

System.out.print("Please enter an employee's first name: ");
empName = input.next();
System.out.print("Please enter their total hours worked: ");
actualHrs = input.nextDouble();


if (actualHrs <=36)
{
normHrs=actualHrs;

}

else
{

normHrs = 36;
bonusHrs = actualHrs - 50;
overHrs = actualHrs -36;
}

if ("bob".equalsIgnoreCase(empName))
{
bonusPay = bonusHrs > 0 ? bonusHrs : 0;
normPay = normHrs * 8; // £8 x 36 hours
overPay = overHrs * 12; // £12 x 36+ hours

}

else
{
bonusPay = bonusHrs >0 ? 20 : 0;
normPay = normHrs * 5.75;
overPay = overHrs * 9.25;

}


}

最佳答案

在 if block 中分配 normPay 时出现错误:

if ("bob".equalsIgnoreCase(empName)) {
bonusPay = bonusHrs > 50 ? bonusHrs : 0;
normPay = actualHrs * 8; // £8 x 36 hours
overPay = overHrs * 12; // £12 x 36+ hours
}

一定是

normPay = normHrs * 8;

关于java - 快到了,只需要通过工资计算朝着正确的方向稍微插入一下?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21983353/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com