java - 字段不会更新

时间:2011-02-11 16:46:43

标签: java

调用AddBirthdayBonus时,余额字段不会更新。任何帮助表示赞赏。

public class class
{
    private float balance;
    private float bob;


    public class(float amount, float bob)
    {
                    balance = amount;
                }
    birthdate = birthday;
    }


    public void AddBirthdayBonus(float todayDate)
    {
      if (todayDate == bob)
      {
     balance += 5;
     }
    }

2 个答案:

答案 0 :(得分:2)

这样的事情有更多工作机会:

public class MyClass{
    private float balance;
    private float bob;


    public MyClass(float balance, float bob)
    {
                    this.balance = balance;
                    this.bob = bob;
    }


    public void AddBirthdayBonus(float todayDate)
    {
      if (todayDate == bob){
        balance += 5;
      }
     }
}

答案 1 :(得分:0)

鲍勃在这里没有任何价值,因此您无法将其与另一个变量进行比较,您应该为其分配一个值,以便能够将其与另一个变量进行比较