set方法在扩展类中找不到符号?

时间:2022-04-09 15:19:38

Here's my code:

这是我的代码:

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;
}
}

When I try to compile, it gives me the error: cannot find symbol's nh and w in the set methods: nHours = nh; wages = w;

当我尝试编译时,它给出了错误:在set方法中找不到符号的nh和w:nHours = nh;工资= w;

Can anyone tell me why and how to fix this? Thanks!

谁能告诉我为什么以及如何解决这个问题?谢谢!

1 个解决方案

#1


2  

For as far as I can see the problem is in your constructor and not in your setters. Parameters and used names don't match -> nh is nHours ( in params ) and w = wages (in params )

就我所知,问题出在你的构造函数中而不是你的setter中。参数和使用的名称不匹配 - > nh是nHours(在参数中)和w =工资(在参数中)

Change to constructor should be made to:

对构造函数的更改应该是:

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;
}

#1


2  

For as far as I can see the problem is in your constructor and not in your setters. Parameters and used names don't match -> nh is nHours ( in params ) and w = wages (in params )

就我所知,问题出在你的构造函数中而不是你的setter中。参数和使用的名称不匹配 - > nh是nHours(在参数中)和w =工资(在参数中)

Change to constructor should be made to:

对构造函数的更改应该是:

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;
}