我们需要进行servlet处理,我们需要使用用户提供的输入来计算员工的净工资。我设法得到了正确的信息但是当获得速率时,输出显示0而不是分配的小时费率,这取决于用户输入的位置。这是我到目前为止的代码块: {
private int rate;
private int grosspay;
private int sss;
private double philhealth;
private double pagibig;
private double tax;
private double deductions;
private int bonus;
private double netpay;
public ComputeBean()
{}
public void setEmployeeid(int employeeid)
{
this.employeeid = employeeid;
}
public int getEmployeeid()
{
return employeeid;
}
public void setEmployeename(String employeename)
{
this.employeename = employeename;
}
public String getEmployeename()
{
return employeename;
}
public void setDepartment(String department)
{
this.department = department;
}
public String getDepartment()
{
return department;
}
public void setHour(int hour)
{
this.hour = hour;
}
public int getHour()
{
return hour;
}
public void setCategory(String category)
{
this.category = category;
}
public String getCategory()
{
return category;
}
public void setPosition(String position)
{
this.position = position;
}
public String getPosition()
{
return position;
}
private void setRate(int rate)
{}
public void computeRate(int rate)
{
getPosition();
if(position.equals("clerk"))
{
setRate(rate = 100);
}
else if(position.equals("sup"))
{
setRate(rate = 200);
}
else if(position.equals("mana"))
{
setRate(rate = 300);
}
else if(position.equals("exec"))
{
setRate(rate = 500);
}
}
public int getRate()
{
return rate;
}
} }
答案 0 :(得分:2)
使用setter时,只需传递值,就像这样
else if(position.equals("exec"))
{
setRate(500);
}
然后确保你的二传手确实做了什么!
private void setRate(int rate)
{
this.rate = rate;
}