This question already has an answer here:
I'm trying to use a variable through a getter, but I cant't seem to access the variable. Here is the code, its a random number generator which is supposed to decide a random color. Any help is greatly appreciated.
import java.util.Random;
public class RNG {
public void startRNG(){
int START = 1;
int END = 10;
Random random = new Random();
for (int idx = 1; idx <= 10; ++idx){
showRandomInteger(START, END, random);
}
}
public void showRandomInteger(int aStart, int aEnd, Random aRandom) {
long range = (long)aEnd - (long)aStart + 1;
long fraction = (long)(range * aRandom.nextDouble());
int randomNumber = (int)(fraction + aStart); // The variable I'm trying to access
}
public int getRandomNumber() {
return randomNumber; // Can't access randomNumber
}
public void colorChooser() {
switch (getRandomNumber()) {
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 7:
break;
case 8:
break;
case 9:
break;
case 10:
break;
}
}
}
Aucun commentaire:
Enregistrer un commentaire