Prashnikaप्रश्निका
Code
About
‹ All Computer Science notes

ISC Practicals and Theory - Quiz Evaluation

Updated 21 Oct 2026

Quiz evaluation means checking the answers of every participant against an answer key, giving each one a score and then finding the highest score and the class average. This version is the straightforward one: everything is written in the main method, which reads and checks the input, evaluates every participant and prints the results.

This note uses a typical set of limits (up to 20 questions and up to 10 participants) and the scoring rule below. An ISC question gives its own limits and marking, which change only the constants and the scoring statement in the program.

Definition

The answer key is a string of $n$ letters, each from A to D, one for each question. The answers of a participant are also $n$ characters: A to D, or X or - when the question is not attempted. The answer to question $i$ is compared with the key letter at the same position.

Scoring rule used here: +1 for a correct answer, 0 for a wrong answer, 0 for an unattempted answer. There is no negative marking.

For example, with key ABCDA and answers AB-XA, questions 1, 2 and 5 match (3 correct), questions 3 and 4 are unattempted and none is wrong, so the score is 3.

Algorithm

  1. Read the number of questions n. If it is not from 1 to 20, print INVALID INPUT and stop.
  2. Read the answer key. It must have exactly n letters, each from A to D; otherwise print INVALID INPUT and stop.
  3. Read the number of participants p. If it is not from 1 to 10, print INVALID INPUT and stop.
  4. Create the arrays ans, score, wrong and skip, one place for each participant. Read the answers of each participant: exactly n characters, each from A to D, or X or - for a question not attempted. Anything else prints INVALID INPUT and stops the run.
  5. Evaluate: for every participant k and question i, if the answer is X or - add 1 to skip[k]; if it equals key.charAt(i) add 1 to score[k]; otherwise add 1 to wrong[k].
  6. Print each participant's score, correct, wrong and unattempted answers. While doing so, add the scores to sum and keep in high the index of the participant with the highest score, replacing it only when a score is strictly greater, so the first one stays on a tie.
  7. Print the highest score, every participant who achieved it, the topper (the first one on a tie) and the class average sum / p to two decimal places.

Program

Everything is written inside main: the checks of the input, the loops that read the answers and score them, and the loops that print the results.

import java.util.Scanner;

/* Program Quiz checks the answers of every participant against an answer key,
   scores each participant and prints the results. */
public class Quiz
{
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter the number of questions (n): ");
        int n = sc.nextInt();                      // number of questions (1 to 20)
        if (n < 1 || n > 20)
        {
            System.out.println("INVALID INPUT");   // n out of range
            return;
        }
        System.out.print("Enter the answer key (" + n + " letters from A to D): ");
        String key = sc.next();                    // answer key: n letters, each from A to D
        boolean valid = key.length() == n;         // stays true while the input is acceptable
        for (int i = 0; valid && i < n; i++)
        {
            char ch = key.charAt(i);
            if (ch < 'A' || ch > 'D')
            {
                valid = false;                     // letter in key is not A to D
            }
        }
        if (!valid)
        {
            System.out.println("INVALID INPUT");   // key of wrong length or with a wrong letter
            return;
        }
        System.out.print("Enter the number of participants (p): ");
        int p = sc.nextInt();                      // number of participants (1 to 10)
        if (p < 1 || p > 10)
        {
            System.out.println("INVALID INPUT");   // p out of range
            return;
        }
        String ans[] = new String[p];              // ans[k] = answers of participant k (n characters)
        int score[] = new int[p];                  // score[k] = number of correct answers of participant k
        int wrong[] = new int[p];                  // wrong[k] = number of wrong answers of participant k
        int skip[] = new int[p];                   // skip[k] = number of unattempted questions of participant k
        for (int k = 0; k < p; k++)
        {
            System.out.print("Enter the answers of participant " + (k + 1)
                + " (" + n + " characters, A to D, X or - if not attempted): ");
            ans[k] = sc.next();
            if (ans[k].length() != n)
            {
                System.out.println("INVALID INPUT");   // answers of wrong length
                return;
            }
            for (int i = 0; i < n; i++)
            {
                char ch = ans[k].charAt(i);
                if ((ch < 'A' || ch > 'D') && ch != 'X' && ch != '-')
                {
                    System.out.println("INVALID INPUT");   // invalid letter
                    return;
                }
            }
        }
        for (int k = 0; k < p; k++)
        {
            for (int i = 0; i < n; i++)
            {
                char ch = ans[k].charAt(i);        // answer given to question i + 1
                if (ch == 'X' || ch == '-')
                {
                    skip[k]++;                     // not attempted
                }
                else if (ch == key.charAt(i))
                {
                    score[k]++;                    // correct
                }
                else
                {
                    wrong[k]++;                    // wrong
                }
            }
        }
        int sum = 0;                               // total of all scores
        int high = 0;                              // index of the first participant with the highest score
        System.out.println();
        for (int k = 0; k < p; k++)
        {
            System.out.println("Participant " + (k + 1) + ": Score = " + score[k]
                + ", Correct = " + score[k] + ", Wrong = " + wrong[k]
                + ", Unattempted = " + skip[k]);
            sum = sum + score[k];
            if (score[k] > score[high])
            {
                high = k;                          // strictly greater, so the first one stays on a tie
            }
        }
        System.out.println("Highest score: " + score[high]);
        System.out.print("Achieved by participant(s):");
        for (int k = 0; k < p; k++)
        {
            if (score[k] == score[high])
            {
                System.out.print(" " + (k + 1));
            }
        }
        System.out.println();
        System.out.println("Topper (first one on a tie): participant " + (high + 1));
        System.out.printf("Class average: %.2f\n", (double) sum / p);
    }
}

Variable description table

VariableData TypePurpose
argsString[]Command line arguments of main; not used
scScannerReads the input typed by the user
nintNumber of questions (1 to 20)
keyStringThe answer key: n letters, each from A to D
validbooleanStays true while the answer key is acceptable
iintPosition of the question or character being examined
chcharThe letter being checked or the answer given to a question
pintNumber of participants (1 to 10)
ansString[]ans[k] is the answers of participant k (n characters)
scoreint[]score[k] is the number of correct answers of participant k
wrongint[]wrong[k] is the number of wrong answers of participant k
skipint[]skip[k] is the number of unattempted questions of participant k
kintIndex of the participant being worked on
sumintTotal of all the scores
highintIndex of the first participant with the highest score

Sample input and output

Sample 1

Enter the number of questions (n): 5
Enter the answer key (5 letters from A to D): ABCDA
Enter the number of participants (p): 3
Enter the answers of participant 1 (5 characters, A to D, X or - if not attempted): AB-XA
Enter the answers of participant 2 (5 characters, A to D, X or - if not attempted): ABCDA
Enter the answers of participant 3 (5 characters, A to D, X or - if not attempted): BBBBB

Participant 1: Score = 3, Correct = 3, Wrong = 0, Unattempted = 2
Participant 2: Score = 5, Correct = 5, Wrong = 0, Unattempted = 0
Participant 3: Score = 1, Correct = 1, Wrong = 4, Unattempted = 0
Highest score: 5
Achieved by participant(s): 2
Topper (first one on a tie): participant 2
Class average: 3.00

Sample 2

Enter the number of questions (n): 3
Enter the answer key (3 letters from A to D): ABC
Enter the number of participants (p): 3
Enter the answers of participant 1 (3 characters, A to D, X or - if not attempted): ABX
Enter the answers of participant 2 (3 characters, A to D, X or - if not attempted): ABC
Enter the answers of participant 3 (3 characters, A to D, X or - if not attempted): ABC

Participant 1: Score = 2, Correct = 2, Wrong = 0, Unattempted = 1
Participant 2: Score = 3, Correct = 3, Wrong = 0, Unattempted = 0
Participant 3: Score = 3, Correct = 3, Wrong = 0, Unattempted = 0
Highest score: 3
Achieved by participant(s): 2 3
Topper (first one on a tie): participant 2
Class average: 2.67

Sample 3

Enter the number of questions (n): 3
Enter the answer key (3 letters from A to D): ABC
Enter the number of participants (p): 1
Enter the answers of participant 1 (3 characters, A to D, X or - if not attempted): AEC
INVALID INPUT

Sample 4

Enter the number of questions (n): 21
INVALID INPUT

One value per line

Dry run

Take the first sample: $n = 5$, key ABCDA, $p = 3$, answers AB-XA, ABCDA and BBBBB. In the evaluation loop for participant 1 (k = 0, answers AB-XA):

ichkey.charAt(i)Decisionscore[0]wrong[0]skip[0]
0AAcorrect100
1BBcorrect200
2-Cnot attempted201
3XDnot attempted202
4AAcorrect302

Participant 2 (ABCDA) matches all five letters, so score[1] becomes 5. Participant 3 (BBBBB) matches only question 2, so score[2] is 1 and wrong[2] is 4. In the printing loop:

kscore[k]sumscore[k] > score[high]high
0333 > 3 is false0
1585 > 3 is true1
2191 > 5 is false1

The highest score is score[1] = 5, achieved by participant 2 alone, and the class average is $9 \div 3 = 3.00$, as in the first sample run.

Variations

  1. Negative marking "Award 1 mark for a correct answer and deduct a fraction of a mark for a wrong one; no marks are deducted for an unattempted question. Display the final score of each participant."
  2. Rank list "Display the participants in descending order of their scores."
  3. Question-wise analysis "For every question, find how many participants answered it correctly."