我很难将hours
andhourlyWage
参数传递给Paycheck
类中的构造函数。问题如下:
symbol: variable hours location : class Paycheck
它在公共课薪水的每个小时或小时工资实例中重复。
代码如下
import java.util.Scanner;
public class PayDayCalculator {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Hourly wage: ");
double hourlyWage = in.nextDouble();
System.out.println("Hours worked: ");
double hours = in.nextDouble();
Paycheck paycheck = new Paycheck(hourlyWage, hours);
System.out.println("Pay: " + paycheck.getPay());
}
}
public class Paycheck {
private double pay = 0;
private double overtime = 0;
private double overtimePay = 0;
/*double hours;
double hourlyWage; */
Paycheck(double hourlyWage, double hours) {
setPay(0);
}
public void setPay(double newPay) {
if (hours > 40) {
overtime = hours % 40;
hours = hours - overtime;
}
overtimePay = hourlyWage * 1.5;
pay = (hours * pay) + (overtime * overtimePay);
}
public double getPay() {
return pay;
}
}