I’m sorry for the title, I wasn’t sure what to call it.
My problem is this, I have a switch statement which randomly chooses a question type as so:
questionType[count] = rad.nextInt(4);
switch (questionType[count])
{
case 0:
questionArray[count] = new Times(count + 1);
((Times) questionArray[count]).askQuestion(question);
break;
case 1:
questionArray[count] = new Add(count + 1);
((Add) questionArray[count]).askQuestion(question);
break;
case 2:
questionArray[count] = new Minus(count + 1);
((Minus) questionArray[count]).askQuestion(question);
break;
case 3:
questionArray[count] = new Divide(count + 1);
((Divide) questionArray[count]).askQuestion(question);
break;
}
What this does is randomly choose a question and then add it to the next array, here is the pesudocode version:
questionType = random(4)
case questionType == 0
do something
break
case questionType == 1
do something
break
case questionType == 2
do something
break
case questionType == 3
do something
break;
Now lets say I do not want any 1’s or 2’s, how do I put that into effect? I was thinking something along the lines of this:
START:
questionType = random(4)
case questionType == 0
if(0 enabled)
{
do something
break
}
case questionType == 1
if(1 enabled)
{
do something
break
}
case questionType == 2
if(2 enabled)
{
do something
break
}
case questionType == 3
if(3 enabled)
{
do something
break;
}
else goto start
But this is very inefficient code and uses a goto, what are the alternatives?
A few ways of implementing but
if you had a store of questions, and whether they were enabled.
Then extract enabled from that and use it’s count as the argument for rad.
so you enabled Questions would be 3 & 4 but would occupy positions 0 & 1 in the list of enabled questions.