当代码执行它时:
A. 不允许您输入员工 ID 的字符串,B. 完全绕过 If/Else 语句。
代码是:
double salary = 0.0;
String employeeID;
System.out.println("\nWhich Employee would you like to see Gross Earning's of? (A, B, C, or ALL)?");
employeeID = input.nextLine();
//if else commnnad to chose which employee details required
if (employeeID == "A")
{
if (employeeA.getHours() > 40)
{
salary = (employeeA.getRate()*40) + employeeA.getOverTimeRate() * (employeeA.getHours() - 40);
}
else
{
salary = employeeA.getRate()*40;
}
}
System.out.printf("You have chosen Employee: %s\nHours Worked: %.2f\nNormal Rate: %.2f\nOver Time Rate: %.2f\nGross Salary: %.2f\n", employeeID, employeeA.getHours(), employeeA.getRate(), employeeA.getOverTimeRate(), salary);
执行时看起来像这样:
您希望查看哪位员工的总收入?(A、B、C 或全部)?您选择了员工: 工作时间: 1.00 正常率: 1.00 加班率: 1.00 总工资: 0.00
我认为我对 IF/Else 语句做错了,因为它似乎根本没有执行此代码。
谢谢夏兰