gpt4 book ai didi

java - 如何计算工时、费率、工资,当我编译时,我收到操作标志错误。请让我知道如何计算它们

转载 作者:行者123 更新时间:2023-12-01 12:07:56 26 4
gpt4 key购买 nike

当我编译它时,我收到错误,操作符号有问题,行代码错误:

Pay = (40 * Rate) + (( Hours - 40) * (1.5 * Rate));

下面是我使用的完整代码。

import java.io.*;

public class Staff {
private int Hours;
private int Rate;
private int Pay;

public Staff() {
Hours = 0;
Rate = 0;
Pay = 0;
}

public void GetEmployee() {
Console console = System.console();
System.out.println(" Please Enter Hours");
Hours = Integer.parseInt(console.readLine());
System.out.println(" Please Enter Rate");
Rate = Integer.parseInt(console.readLine());
}

public void ShowEmployee() {
Console console = System.console();
System.out.println(" Pays = " + Pay);
}

public void ComputePay() {
if (Hours > 40) {
Pay = (40 * Rate) + ((Hours - 40) * (1.5 * Rate));
} else {
Pay = (Hours * Rate);
}
}
}

最佳答案

//添加转换为'int'

Pay = (int) ((40 * Rate) + ((Hours - 40) * (1.5 * Rate)));

关于java - 如何计算工时、费率、工资,当我编译时,我收到操作标志错误。请让我知道如何计算它们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27465427/

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