遇到的问题:无法调用随机生成器的 getInstance() 方法,不知道问题出在哪里
/*File DiceRoll.java
-
- This program simulates to roll some dices and tell the amount of all numbers on the dices.
*/
import acm.program.;
import acm.util.;
public class DiceRoll extends ConsoleProgram {
private static final int NUM_SIDES=6;
public void run() {
int Num_Dices=readInt("Number of dices:");
int MaxRoll=Num_Dices*NUM_SIDES;
int numRoll=0;
while(true) {
int roll= rollDice(Num_Dices);
numRoll++;
if(roll==MaxRoll) break;
println("rolled"+roll);
}
println("rolled"+MaxRoll+"after"+Num_Dices+"rolls");
}
private int rollDice(int Num_Dices) {
int total=0;
for(int i=0; i< Num_Dices; i++) {
total+=rgen.nextInt(1,NUM_SIDES);
}
return total;
}
private RandomGenerator rgen= RandomGenerator.getInstance();