This is the code:
Expand|Select|Wrap|Line Numbers
- public void askQuestions(String[] questions, String[] answers) {
- int count = 0;
- int point = 0;
- int[] A = new int[questions.length];
- int[] B = new int[A.length];
- int countA = A.length;
- int countB = 0;
- Random generator = new Random();
- for (int i = 0; i < A.length; i++){
- A[i] = i;
- }
- while (countA > 0){
- int pos = generator.nextInt(A.length);
- B[countB] = A[pos];
- countB++;
- for (int i = pos; i < A.length - 1; i++){
- A[i] = A[i + 1];
- }
- countA--;
- }
- for(int j = 0; j < questions.length; j++) {
- timeForMore = true;
- int randomIndex = B[j];
- String input = JOptionPane.showInputDialog(null, questions[randomIndex]);
- if(answers[randomIndex].equalsIgnoreCase(input))
- count++;
- point++;
- if(!timeForMore)
- break;
- }
- JOptionPane.showMessageDialog(null, "You answered " + count +
- " out of " + questions.length +
- " questions correctly.");
- }