开发者

java - field won't update [closed]

开发者 https://www.devze.com 2023-02-10 12:42 出处:网络
Closed. This question needs debugging details. It is not currently accepting answers. Edit the question to include desired behavior, a specific problem or error, and the shortest code nece
Closed. This question needs debugging details. It is not currently accepting answers.

Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.

Closed 6 years ago.

Improve this question 开发者_运维问答

The balance field won't update when AddBirthdayBonus is called. Any help is appreciated.

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


Something like this has more chances to work:

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


Bob has no value here so you can't compare it with another variable, you should assign a value to it to be able to compare it with another variable

0

精彩评论

暂无评论...
验证码 换一张
取 消