Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple and single choice test

Tags:

java

android

I am working on a Single choice and Multiple choice test.

I have couple of questions and 4 answers for each question.

I am shuffling the answers as each answer is assigned to radio button. This is how i am shuffling the arraylist where Random is a arraylist with items and r1,r2,r3,r4 are radio buttons.

random.add(val);
Collections.shuffle(random);


r1.setText(random.get(0));
r2.setText(random.get(1));
r3.setText(random.get(2));
r4.setText(random.get(3));

I am able to display the answers in jumbled way but when i select the answer i need to show that the answer is correct or wrong.

Sample question and options.
1. which language is used for android programming?
 A.PHP
 B.JAVA
 C.C
 D.C++

Correct answer is B i need to display that correct answer is B.

How to acheive this.

EDIT: I have tried this:

Onclick of each radio button assign the value A and compare the value with xml value if its correct display correct but when i jumble its will not work.

EDIT 2 xml

<Question no="1" text="Which Programming language is used in android develoment" type="SCA" noc="4" jumble="NO" correctans="PHP">
<choice a = "PHP" flag="A"> 
<choice b = "JAVA" flag="B"> 
<choice c = "C" flag="C"> 
<choice d = "C++" flag="D"> 
like image 591
Goofy Avatar asked Dec 01 '12 07:12

Goofy


People also ask

What is the difference between single-choice and multiple-choice?

The main difference between single and multiple-choice questions is that candidates can choose only one answer for a single-choice question, while for multiple-choice questions, they can choose one or more correct answers.

What is multiple-choice type of test?

Multiple choice. Multiple choice questions are composed of one question (stem) with multiple possible answers (choices), including the correct answer and several incorrect answers (distractors).

What is a single-choice exam?

In a single-choice question, there is only a single correct answer and the rest of the options are distractors. Learners must completely understand the content before they pick the only correct answer form the list of options. They are closed-ended questions where the answer options are already provided.

What is MCQ and Scq?

Klaxoon offers 9 types of Quiz questions used in the Quiz, Adventure, and Memo activities. Single choice question (SCQ) Participants select one answer from several options. Example: Spot the odd one out. Multiple choice question (MCQ)


2 Answers

You can create a hashmap with Option-isOptionCorrect pair. Like for your case:

HashMap<String, Boolean> choices = new HashMap<String, Boolean>();
choices.put("PHP", false);
choices.put("JAVA", true);
choices.put("C", false);
choices.put("C++", false);

Now shuffle the key-value pairs. Your correct choice will be one which has value true in the HashMap.

like image 84
Jainendra Avatar answered Oct 19 '22 03:10

Jainendra


Egor is clear for what he is suggesting but I'll let you work with your current implementations.

class Option{
      //You can add any other parameters if required.
      String optionText;
      boolean isAnswer;
}

// Use arraylist of Option class like this ArrayList<Option> options = new ArrayList<Option>(); // in your case random

// Now suffle it. Collections.shuffle(options); // get the user selected option and verify using. if(options.get(userSelectedOptionPosition).isAnswer){ //show "You are Correct!" }else{ // show "You are In correct!" }

Hope this will help you.

like image 24
Ajay Kumar Meher Avatar answered Oct 19 '22 02:10

Ajay Kumar Meher