2011-02-11 89 views
-3

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

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

你怎么知道它没有更新?你在哪里使用它,它没有正确显示? – Poindexter 2011-02-11 16:49:02

回答

0

Bob有没有价值,你在这儿不能将其与其他变量相比,你应该值分配给它能够将其与另一个变量

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