Create a Wheel class. The class will simulate spins of the roulette wheel in the range 1-n. Create a constructor that takes 3 parameters: a seed (int) a lower bound m (int) an upper bound n (int) Create a method spin() which returns the next random string generated by roll of the wheel. This method should return a string. You can use Random() to generate a number from 0 to (n-1-m) and then add m to get a number in the specified range. Use Random() to generate a bigInteger (you want large numbers) and then convert it to a String using the toString() method
Current code:
import java.io.*;
import java.util.*;
public class Wheel {
public int seed, m, n;
public Wheel(int seed, int m, int n) {
seed = 100000001;
Random random = new Random(seed);
for(int x = 0; x < 10; x++) {
System.out.println(100 * random.nextDouble());
}
}
public String spin() {
seed = 100000001;
//m = 1;
//n = 100000001;
String letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
StringBuilder words = new StringBuilder();
Wheel random = new Wheel(seed, m, n);
while (words.length() < 10) {
int index = (int) (random.nextInt() * letters.length());
words.append(letters.charAt(index));
}
String wordMade = words.toString();
return wordMade;
}
}
Can't seem to get this to work and I'm not sure why. Any help would be appreciated.
Aucun commentaire:
Enregistrer un commentaire