Pls help me - how to draw out questions wrongly answered from a pool of array
Hi, I'm desparately trying to know how to do the code whereby I can dispaly the wrong questions answered from category chosen. There are 4 categories with 5 questions each and I need to dispaly all the wrong questions. So far my code only show the question 1 all the time.:confused:
Code:
import javax.swing.*;
public class Quiz {//Quiz Class
public final static int NOOFQUESTION = 5;
public final static int POOLSIZE = 20;
public final static int CAT1 = 0;
public final static int CAT2 = 1;
public final static int CAT3 = 2;
public final static int CAT4 = 3;
private Question[] pool;
private Question[] mcqs;
private int currentCategory;
private int currentQuestionIndex;
private String pic;
private String result;
private String wrongquestion;
//constructor
public Quiz() {
pool = new Question[POOLSIZE];
mcqs = new Question[NOOFQUESTION];
pool[0] = new Question(CAT1, "cat1_q1_question", "q1_choice1", "q1_choice2", "q1_choice3", "q1_choice4", 2);
pool[1] = new Question(CAT1, "cat1_q2_question", "q2_choice1", "q2_choice2", "q2_choice3", "q2_choice4", 2);
pool[2] = new Question(CAT1, "cat1_q3_question", "q3_choice1", "q3_choice2", "q3_choice3", "q3_choice4", 2);
pool[3] = new Question(CAT1, "cat1_q4_question", "q4_choice1", "q4_choice2", "q4_choice3", "q4_choice4", 2);
pool[4] = new Question(CAT1, "cat1_q5_question", "q5_choice1", "q5_choice2", "q5_choice3", "q5_choice4", 2);
pool[5] = new Question(CAT2, "cat2_q1_question", "choice1", "choice2", "choice3", "choice4", 2);
pool[6] = new Question(CAT2, "cat2_q2_question", "choice1", "choice2", "choice3", "choice4", 3);
pool[7] = new Question(CAT2, "cat2_q3_question", "choice1", "choice2", "choice3", "choice4", 2);
pool[8] = new Question(CAT2, "cat2_q4_question", "choice1", "choice2", "choice3", "choice4", 3);
pool[9] = new Question(CAT2, "cat2_q5_question", "choice1", "choice2", "choice3", "choice4", 2);
pool[10] = new Question(CAT3, "cat3_q1_question", "choice1", "choice2", "choice3", "choice4", 2);
pool[11] = new Question(CAT3, "cat3_q2_question", "choice1", "choice2", "choice3", "choice4", 3);
pool[12] = new Question(CAT3, "cat3_q3_question", "choice1", "choice2", "choice3", "choice4", 2);
pool[13] = new Question(CAT3, "cat3_q4_question", "choice1", "choice2", "choice3", "choice4", 3);
pool[14] = new Question(CAT3, "cat3_q5_question", "choice1", "choice2", "choice3", "choice4", 2);
pool[15] = new Question(CAT4, "cat3_q1_question", "choice1", "choice2", "choice3", "choice4", 2);
pool[16] = new Question(CAT4, "cat3_q2_question", "choice1", "choice2", "choice3", "choice4", 3);
pool[17] = new Question(CAT4, "cat3_q3_question", "choice1", "choice2", "choice3", "choice4", 2);
pool[18] = new Question(CAT4, "cat3_q4_question", "choice1", "choice2", "choice3", "choice4", 3);
pool[19] = new Question(CAT4, "cat3_q5_question", "choice1", "choice2", "choice3", "choice4", 2);
}
public void setupMCQs(int cat) {
currentCategory = cat;
int j = 0;
for (int i = 0; i < pool.length; i++) {
if (pool[i].getCategory() == currentCategory) {
mcqs[j] = pool[i];
j++;
}//end if
}//end for
}
public String getCurrentCategory() {
if (currentCategory == CAT1) {
return "Category 1";
}
if (currentCategory == CAT2) {
return "Category 2";
}
if (currentCategory == CAT3) {
return "Category 3";
} else {
return "Category 4";
}
}
public void nextCategory() {
currentCategory++;
}
public void nextQuestion() {
currentQuestionIndex++;
}
public boolean isLastQuestion() {
if (currentQuestionIndex == mcqs.length) {
return true;
} else {
return false;
}
}
public int getCurrentQuestionIndex() {
return currentQuestionIndex;
}
public Question getCurrentQuestion() {
return mcqs[currentQuestionIndex];
}
public void setSelectedAnswer(int ans) {
mcqs[currentQuestionIndex].setSelected(ans);
}
public void setPic(String p) {
pic = p;
}
public String getPic() {
return pic;
}
public String getResult() {
int score = 0;
int j = 0;
for (int i = 0; i < mcqs.length; i++) {
if (mcqs[i].getCorrect() == mcqs[i].getSelected()) {
score++;
}
if (mcqs[i].getCorrect() != mcqs[i].getSelected());
mcqs[i] = mcqs[j];
mcqs[j].getQuestionText();
}
result = "You've answered " + "\t" + score + " questions correctly" +
"\n You've chosen the wrong answer(s) for the following question(s)" + "\n" + mcqs[j].getQuestionText();
return result;
}//end of Quiz Class
}
the result method is the part that I need to know how cos this will be used in the main application program.
I really hope someone can give me some pointers. Am very lost. Tks.