Try this:-
// boolean promote, promotes a level up
public boolean promote()
{
if (level.equals("apprentice"))
{
level = "wizard";
galleons +=100;
return true;
}
else if (level.equals("wizard"))
{
level = "mage";
galleons +=100;
return true;
}
else if (level.equals("mage"))
{
level = "sorcerer";
galleons +=100;
return true;
}
else if (level.equals("sorcerer"))
{
level = "shaman";
galleons +=100;
return true;
}
else if (level.equals("shaman"))
{
return false;
}
return true;
}
If you need to access the variable from main()
then you need to declare the variable as static.
public static void main(String str[]){
Magician magg=new Magician("Harry#wizard#broom#staff");
System.out.println("Level before promote is ::"+level);
magg.promote();
System.out.println("Level after promote is::"+level);
}
Output :-
Level before promote is ::wizard
Level after promote is::mage
Its working now.
Hope it will help you.