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
- Read the number of questions
n. If it is not from 1 to 20, printINVALID INPUTand stop. - Read the answer key. It must have exactly
nletters, each from A to D; otherwise printINVALID INPUTand stop. - Read the number of participants
p. If it is not from 1 to 10, printINVALID INPUTand stop. - Create the arrays
ans,score,wrongandskip, one place for each participant. Read the answers of each participant: exactlyncharacters, each from A to D, orXor-for a question not attempted. Anything else printsINVALID INPUTand stops the run. - Evaluate: for every participant
kand questioni, if the answer isXor-add 1 toskip[k]; if it equalskey.charAt(i)add 1 toscore[k]; otherwise add 1 towrong[k]. - Print each participant's score, correct, wrong and unattempted answers. While doing so, add the scores to
sumand keep inhighthe 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. - Print the highest score, every participant who achieved it, the topper (the first one on a tie) and the class average
sum / pto 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
| Variable | Data Type | Purpose |
|---|---|---|
args | String[] | Command line arguments of main; not used |
sc | Scanner | Reads the input typed by the user |
n | int | Number of questions (1 to 20) |
key | String | The answer key: n letters, each from A to D |
valid | boolean | Stays true while the answer key is acceptable |
i | int | Position of the question or character being examined |
ch | char | The letter being checked or the answer given to a question |
p | int | Number of participants (1 to 10) |
ans | String[] | ans[k] is the answers of participant k (n characters) |
score | int[] | score[k] is the number of correct answers of participant k |
wrong | int[] | wrong[k] is the number of wrong answers of participant k |
skip | int[] | skip[k] is the number of unattempted questions of participant k |
k | int | Index of the participant being worked on |
sum | int | Total of all the scores |
high | int | Index 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.00Sample 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.67Sample 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 INPUTSample 4
Enter the number of questions (n): 21
INVALID INPUTDry 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):
| i | ch | key.charAt(i) | Decision | score[0] | wrong[0] | skip[0] |
|---|---|---|---|---|---|---|
| 0 | A | A | correct | 1 | 0 | 0 |
| 1 | B | B | correct | 2 | 0 | 0 |
| 2 | - | C | not attempted | 2 | 0 | 1 |
| 3 | X | D | not attempted | 2 | 0 | 2 |
| 4 | A | A | correct | 3 | 0 | 2 |
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:
| k | score[k] | sum | score[k] > score[high] | high |
|---|---|---|---|---|
| 0 | 3 | 3 | 3 > 3 is false | 0 |
| 1 | 5 | 8 | 5 > 3 is true | 1 |
| 2 | 1 | 9 | 1 > 5 is false | 1 |
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
- 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."
- Rank list "Display the participants in descending order of their scores."
- Question-wise analysis "For every question, find how many participants answered it correctly."