【问题标题】:Can't assign a specific value to a variable无法将特定值分配给变量
【发布时间】:2018-03-14 02:05:58
【问题描述】:

我们需要进行 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;
}

} }

【问题讨论】:

标签: java html css servlets


【解决方案1】:

使用 setter 时,只需传递值,就像这样

else if(position.equals("exec"))
{
    setRate(500);
}

然后确保你的 setter 确实做了一些事情!

private void setRate(int rate) 
{
    this.rate = rate;
}

【讨论】:

  • 费率仍为 0
  • 您确定在将费率信息显示到屏幕之前调用了计算费率吗?
  • 天哪,这就是我想念的东西,哈利路亚,你是救命的朋友
猜你喜欢
  • 2019-07-18
  • 2015-06-19
  • 1970-01-01
  • 1970-01-01
  • 2019-04-03
  • 2023-03-24
  • 1970-01-01
  • 2020-11-21
  • 2013-03-05
相关资源
最近更新 更多