Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 5    Views: 49

krompa
Lost but trying
Profile
Posts: 257
Reg: Jun 14, 2013
Bristol
8,820
11/11/14 07:28 AM (9 years ago)

Android Interactive Quiz - Questions getting gradually more difficult?

A number of good quiz apps out there start off easy at question 1 and gradually get harder as the quiz progresses. Think of the gameplay in a TV show like Who Wants to be a Millionaire for instance. I am trying to replicate this increment in difficulty in the Interactive Quiz Plugin - but require help from BT Android ninjas. I have started by adding a difficulty level called "Level" to each question in a test batch of 12 questions. The Levels range from 1 to 5. So the child items now look like this: {"itemId":"XX","itemType":"BT_quizQuestion","Level":1,"questionText":"What is the capital city of Spain?","correctAnswerText":"Madrid","incorrectText1":"Barcelona","incorrectText2":"Valencia","incorrectText3":"Seville"}, {"itemId":"YY","itemType":"BT_quizQuestion","Level":2,"questionText":"Bruce Springsteen is also known as ...","correctAnswerText":"The Boss","incorrectText1":"Prince of Darkness","incorrectText2":"God of Thunder","incorrectText3":"Old Pete"}, {"itemId":"ZZ","itemType":"BT_quizQuestion","Level":3,"questionText":"Where in the body would you find a metatarsal bone?","correctAnswerText":"Foot","incorrectText1":"Hand", "incorrectText2":"Neck","incorrectText3":"Ear"}, ... etc At approx line 945 of the interactive quiz plugin is this section //randomize questions from pool then grab "x" number for quiz if(questionPool.size() > 0 && (quizRandomizeQuestions.equals("1") || quizRandomizeQuestions.toUpperCase().equals("YES") )){ Collections.shuffle(questionPool); childItems = new ArrayList<BT_item>(); for (int i = 0; i < questionPool.size(); i++){ if(i < quizNumberOfQuestions){ BT_item thisQuestion = questionPool.get(i); childItems.add(thisQuestion); }else{ break; } }//end for each }else{ //showAlert("No Questions?", "This quiz does not have any questions associated with it?"); } I have played around and added these two lines to the gap in the code above: String level = BT_strings.getJsonPropertyValue(thisQuestion.getJsonObject(), "Level", "") if(level.equals("1")) childItems.add(thisQuestion); which successfully adds only questions with a Level rating of 1. So some progress there. Any thoughts on how to iterate through to select just one Level 1, one Level 2, one Level 3, one Level 4 and one Level 5 question for a 5-question quiz? Maybe the answer lies in a for loop or similar, but when I try this, I get error messages related to ArrayLists and Strings. I'm at the edge of my capability here (as always).
 
Dusko
Veteran developer
Profile
Posts: 998
Reg: Oct 13, 2012
Beograd
22,680
like
11/11/14 08:18 AM (9 years ago)
A loop with a couple of strategically placed if's will do the trick.
 
krompa
Lost but trying
Profile
Posts: 257
Reg: Jun 14, 2013
Bristol
8,820
like
11/11/14 08:54 AM (9 years ago)
Do you think this is he right way to go about it? for loop that iterates through question pool if level.equals("1") && childItems does not contain a Level 1 question then add this question to childItems; else if level.equals("2") && childItems does not contain a Level 2 question then add this question to childItems; else if level.equals("3") && childItems does not contain a Level 3 question then add this question to childItems; else if level.equals("4") && childItems does not contain a Level 4 question then add this question to childItems; else if level.equals("5") && childItems does not contain a Level 5 question then add this question to childItems; end loop Is finding 'childItems does not contain a Level 1 question' possible?
 
Dusko
Veteran developer
Profile
Posts: 998
Reg: Oct 13, 2012
Beograd
22,680
like
11/11/14 01:06 PM (9 years ago)
>Is finding 'childItems does not contain a Level 1 question' possible? Of course it is. You may need several loops, one after another. Introduce one or more "parallel" arrays, say of type boolean, and in the first loop record which child item does not have Level 1 question. You should have five loops for five levels, and you may also have five parallel arrays. Only then should you use yet another loop to ask all those if statements from the message above. Clear as mud or transparent as air?
 
krompa
Lost but trying
Profile
Posts: 257
Reg: Jun 14, 2013
Bristol
8,820
like
11/11/14 01:29 PM (9 years ago)
Clear as mud at the minute.
 
krompa
Lost but trying
Profile
Posts: 257
Reg: Jun 14, 2013
Bristol
8,820
like
11/15/14 05:59 AM (9 years ago)
If brain fails ask stackoverflow. This is a very neat solution: childItems = new ArrayList<BT_item>(); for(int i=0; i<5; i++){ for(BT_item item:questionPool){ // loop through all the items in the question pool String level = BT_strings.getJsonPropertyValue(item.getJsonObject(), "Level", ""); if(level.equals(String.valueOf(i+1))) { childItems.add(item); // add 1 to count because it starts at 0, but levels start at 1 break; // found a question, so break the inner loop (but not the outer one) } }
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.