Dave Spell Dave Spell - 16 days ago 5
Java Question

Looping and Keeping the count

I would like this method called "roll" to count down my int called "spacePoints" each time its called. It works however, it starts from 100 each time. I need it to start where the points were left off each time the method is called.

int spacePoints = 100;

public void roll (){
pointsRolled = ((int) (Math.random() * 10)+ 1);
if (pointsRolled % 3 ==0){
System.out.println("You must fight!!!");

} else {
spacePoints = spacePoints- pointsRolled;
System.out.println("You have " + spacePoints + " to go.");

}

}

Answer

Your question is a bit unclear, as @John3136 mentioned, but I'm betting you need to read more about the static keyword and understand class members.