这是我的代码:
public class PTEmployee extends Employee
{
private int nHours;
private float wages;
public PTEmployee(String name, String ssn, String position, Date dateOfBirth,
float pay, int nHours, float wages)
{
super(name,ssn,position,dateOfBirth,pay);
nHours = nh;
wages = w;
pay = 0;
}
public void raise(float amount)
{
wages = wages + amount;
pay = nHours * wages;
}
public void setNHours(int nh)
{
nHours = nh;
}
public void setWages(float w)
{
wages = w;
}
public int getNHours()
{
return nHours;
}
public float getWages()
{
return wages;
}
}
当我尝试编译时,它给我一个错误:在set方法中找不到符号的nh和w: nHours = nh; 工资= w;
谁能告诉我为什么以及如何解决此问题?谢谢!
答案 0 :(得分:2)
就我所知,问题出在您的构造函数中,而不是您的二传手中。参数和使用的名称不匹配-> nh是nHours(以params表示),w =工资(以params表示)
应将构造函数更改为:
public PTEmployee(String name, String ssn, String position, Date dateOfBirth,
float pay, int nHours, float wages)
{
super(name,ssn,position,dateOfBirth,pay);
this.nHours = nHours;
this.wages = wages;
pay = 0;
}