You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
state property has null value if the object was created with zero gumballs like: new GumballMachine(0)
Inside GumballMachine.java you have the following:
State soldOutState; // soldOutState is null
// other properties
State state = soldOutState; // state is null
public GumballMachine(int numberGumballs) {
soldOutState = new SoldOutState(this); // soldOutState has a new reference
// other code
this.count = numberGumballs;
if (numberGumballs > 0) { // if this is false, then state will still be null
state = noQuarterState;
}
}
So, to fix this it's better to add else statement in the constructor to give state the new soldOutState value, like:
if (numberGumballs > 0) { // if this is false, then state will be soldOutState
state = noQuarterState;
} else {
state = soldOutState;
}
The text was updated successfully, but these errors were encountered:
state
property hasnull
value if the object was created with zero gumballs like:new GumballMachine(0)
Inside GumballMachine.java you have the following:
So, to fix this it's better to add
else
statement in the constructor to givestate
the newsoldOutState
value, like:The text was updated successfully, but these errors were encountered: