2011-02-11 94 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; 
     } 
    } 
}