My question is... what is the int times for? i dont understand what i am supposed to do with it.
Here are the instructions about this method:
String[] generate(String symbol, int times)
In this method you should use the grammar to randomly generate the given number of occurrences of the given symbol and you should return the result as an array of Strings. For any given nonterminal symbol, each of its rules should be applied with equal probability. It should throw an IllegalArgumentException if the grammar does not contain the given nonterminal symbol or if the number of times is less than 0.
The full list of instructions are here if the instructions on this method are not clear enough:
Additionally, here is my code without the int times...
public String generate(String symbol){
if(symbol == null || symbol.isEmpty())
throw new IllegalArgumentException();
if(!grammarContains(symbol))
return symbol + " "; //Ends the recursive calls if the symbol is a terminal string.
String generated = ""; //Starts the string used to store the strings of all the recursive calls.
String[] temp = myMap.get(symbol); //Grabs the string array of the key being used at the moment.
for(String value: temp[RANDOM.nextInt(temp.length)].trim().split("[ \t]+"))
generated += generate(value); //Recursive call till the last value is a terminal string.
return generated;
}