Leo, thank you for your understanding regarding the community rules. It's not something I have great joy for but it's something I committed to upon becoming a moderator. I do without a doubt enjoy assisting members with code specific issues.
I wrote a little example that has relations to your initial code. You can see the many uses of the simple line generating a random number. Remember, the parameter given to
nextInt is an inclusive number in that it includes 0 up to and excluding that number. So in this case below, someone will correct me if I'm wrong.. it includes numbers 0-9. Give this a study and post any questions you may have. There's certainly more efficient ways to do this I'm sure, but I think it's sufficient for now. If you have improvements definitely post them if you want.
import java.util.Random;
public class Question {
String[] questions = new String[10];
public Question() {
// eight prefixes to be chosen at random
String [] prefix =
{"What", "How", "When", "Why", "Are", "Do", "Then", "Like"};
// eight basic, first category words to be chosen at random
String [] wordsOne =
{"time", "day", "cool", "hungry", "is", "can't", "you", "enjoy"};
// eight basic, second category words to be chosen at random
String [] wordsTwo =
{"who", "awesome", "okay", "really", "turtle", "move", "look", "life"};
// eight basic, third category words to be chosen at random
String [] wordsThr =
{"money", "cheese", "run", "couch", "concept", "it", "cat", "factor"};
// only one suffix
String suffix = "?";
Random rand = new Random();
// choose random prefixes and words to make randomly made questions
for (int i = 0; i < questions.length; ++i) {
questions[i] =
prefix[rand.nextInt(8)] + " "
+ wordsOne[rand.nextInt(8)] + " "
+ wordsTwo[rand.nextInt(8)] + " "
+ wordsThr[rand.nextInt(8)] + suffix;
}
}
public String[] generateRandomQuestion() {
Random randomGen = new Random();
System.out.println("\n--Your random question is: \n" +
questions[randomGen.nextInt(10)]);
return questions;
}
public String[] generateRandomQuestions() {
Random randomGen = new Random();
System.out.println("\n--Your random questions are: ");
for (int q = 0; q < questions.length * 2; ++q) {
System.out.println(questions[randomGen.nextInt(10)]);
}
return questions;
}
public static void main(String[] args) {
Question q = new Question();
q.generateRandomQuestion();
q.generateRandomQuestions();
}
}
Sample output shows this:
--Your random question is:
Are hungry who cat?
--Your random questions are:
Then hungry okay cat?
Are hungry life run?
Are day who concept?
When you look run?
When you look run?
Are day who concept?
When you look run?
Why cool okay run?
Are hungry life run?
What you look cat?
Are day who concept?
Do is awesome money?
Then hungry okay cat?
Are day who concept?
Are hungry who cat?
Then hungry okay cat?
Are day who concept?
Do is awesome money?
Why cool okay run?
Then hungry okay cat?
Another change from the code, highlighted below:
...
String[] questions = new String[20];
...
public String[] generateRandomQuestions() {
Random randomGen = new Random();
System.out.println("\n--Your random questions are: ");
for (int q = 0; q < questions.length; ++q) {
System.out.println(questions[q]);
}
return questions;
}
...
shows this for output, note the difference->instead of choosing random strings- outputs all randomly-made strings:
--Your random question is:
How enjoy move factor?
--Your random questions are:
Do time turtle concept?
Do enjoy look money?
How enjoy move factor?
When you who factor?
Like can't look cat?
Why you life it?
Then can't okay it?
Do cool awesome money?
Are enjoy life it?
Do day look cat?
When hungry who cheese?
How enjoy look money?
Do day move cat?
Like you who cheese?
Are time okay money?
Then hungry okay money?
When time turtle concept?
Are day turtle it?
What can't awesome concept?
Then can't look it?