Question

I am developing a quiz game, where I have to get random activities on answering the questions as to avoid the questions in same order. I have fixed this by using switch

However, the problem is that I may return to questions which I've already answered, so I now have to code something that avoids the player to go to previous questions by the random generator.

I've done this so far;

  Random rand = new Random();
  int number = rand.nextInt(10);
  Intent intent = null;

       switch(number){
       case 0: intent = new Intent(MainActivity.this, Question001.class);
       break;
       case 1: intent = new Intent(MainActivity.this, Question002.class);
       break;

       //etc....
       }
       startActivity(intent);           

This brings randomly activities on button click, however I want to disable previously visited questions meaning, if a person has answered the question from class Question002, he must not be able to (never and never) get this question once more, as this will result in his gaining of extra points from earlier questions. How do I randomly get questions on button click only ONCE, so they won't appear again? I hope my question is understood.

Every question is stored in its own class (Question001, Question002.... Question009)

No correct solution

OTHER TIPS

Follow these steps:

  1. Create an ArrayList (or a List simply) and add all your Questions to it. Remember this only holds the questions for shuffling. Do not use it for any other purpose.
  2. Then do a shuffle using Collections.shuffle(question).
  3. Ask the question on top (question.get(0));
  4. After this has been answered remove it from the List. This will ensure it is never shown again.
  5. Repeat steps 2 - 5 till your List size is greater than zero.

Let me know if it is unclear.

use

ArrayList<Integer> number = new ArrayList<Integer>();
for (int i = 1; i <= 10; ++i) number.add(i);
Collections.shuffle(number);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top