0

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!

Rajesh Pantula
  • 10,061
  • 9
  • 43
  • 52
  • You might want to rephrase your question. The wording is a bit confusing. Do you have total 5 cards where each card has "hint" & "answer". Are you having any nested cards? why do you have to generate random between 1 & 10 if you only have 5 cards? – Rajesh Pantula Aug 25 '16 at 23:58
  • Ok, I don't think I described my problem as clearly as possible. Theres a question for the user to answer. There are 5 cards. Each card has a "Hint" and the actual answer. Example: Card 1: Hint: This is hint for card 1 Answer: This is answer for Card 1 Card 2: Hint: This is hint for card 2 Answer: This is answer for Card 2 ... and so on up to Card 5. – user4761654 Aug 26 '16 at 00:02
  • I need to randomize these cards because it will be used in a classroom environment, where students are given tablets to solve these problems. It's supposed to decrease cheating – user4761654 Aug 26 '16 at 00:03
  • The questions are coming in a string array right now, in the following format: Hint1|Ans1|Hint2|Ans2|Hint3|Ans3... etc – user4761654 Aug 26 '16 at 00:04

1 Answers1

0

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 
             Collections.shuffle(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 =]

whyn0t
  • 301
  • 2
  • 14