user4761654 user4761654 - 1 year ago 79
Java Question

Randomize Quiz Set, each solution has two parts

I have a Quiz program I'm working on. The user is presented with a question and is presented with 5 cards to choose from. The user has to select the correct card that answers the question.

Each card has two unique data. The card has a "Hint" field and the actual "Answer" field.

The Hint is specific for the Answer, which is specific to that particular card.

There's a total of 5 cards. Again, each card has a Hint and Answer.

I need to randomize these cards and place them in different orders. Currently, I'm generating a random number between 1-10 and then manually "randomizing" the cards by rearranging the hints/answers.

Is there a better approach of randomizing the cards? Any tips will be greatly appreciated!

Answer Source

you have to define a class Card containing the answer and the hint and whether the answer is right or not (this last detail is just a suggestion)

       public class Card {
           String hint;// contains the hint
           String answer;// contains the answer
           boolean isItTrueAnswer;// is the answer true ??
           boolean isItRight(){
                   return itItTrueAnswer;
           // ... getters setters and maybe serialisation


the other part is to define the question part

       public class Question{
       String theQuestion;
       ArrayList<Card> answers;// each question has N answers means N cards 

       // create a question 
       Question(String question,ArrayList<Card> ans){
             this.theQuestion = question;
             answers = ans;
             // here you shuffle the answers 
       public boolean checkAnswer(int chosenCardIndex){

                 return answer.get(chosenCardIndex).isItRight();


this is just illustrative, you still have to adapt it to your program, goodluck =]

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download