Categories

# Quiz Java Program ISC 2017

The result of a quiz competition is to be prepared as follows:

The quiz has five questions with four multiple choices (A, B, C, D), with each question carrying 1 mark for the correct answer. Design a program to accept the number of participants N such that N must be greater than 3 and less than 11. Create a double-dimensional array of size (N * 5) to store the answers of each participant row-wise. Calculate the marks for each participant by matching the correct answer stored in a single-dimensional array of size 5. Display the scores for each participant and also the participants(s) having the highest score.

Example: If the value of N = 4, then the array would be:

 Q1 Q2 Q3 Q4 Q5 Participant 1 A B B C A Participant 2 D A D C B Participant 3 A A B A C Participant 4 D C C A B
 Key to the question: D C C A B

Note: Array entries are line fed (i.e. one entry per line)

Test your program for the following data and some random data.

Example 1:
INPUT:
N = 5

`Participant 1 D A B C CParticipant 2 A A D C BParticipant 3 B A C D BParticipant 4 D A D C BParticipant 5 B C A D DKey: B C D A A`

OUTPUT:

`Scores:Participant 1 = 0Participant 2 = 1Participant 3 = 1Participant 4 = 1Participant 5 = 2Highest Score: Participant 5`

Example 2:

INPUT:
N = 4

```Participant 1 A C C B DParticipant 2 B C A A CParticipant 3 B C B A AParticipant 4 C C D D BKey: A C D B B
```

OUTPUT:

``````Scores:
Participant 1 = 3
Participant 2 = 1
Participant 3 = 1
Participant 4 = 3
Highest score:
Participant 1
Participant 4``````

Example 3:

INPUT:
N = 12
OUTPUT:
INPUT SIZE OUT OF RANGE.

``````import java.io.*;
class Quiz{
public static void main(String args[])
throws IOException{
System.out.print("Number of participants: ");
int highest = 0;
if(n < 4 || n > 10){
System.out.println("INPUT SIZE OUT OF RANGE.");
return;
}
char q[][] = new char[n][5];
char a[] = new char[5];
int score[] = new int[n];
System.out.println("Key to the questions:");
for(int i = 0; i < a.length; i++)
for(int i = 0; i < n; i++){
System.out.println("Participant " + (i + 1));
for(int j = 0; j < 5; j++){
if(q[i][j] == a[j])
score[i]++;
}
if(highest < score[i])
highest = score[i];
}
for(int i = 0; i < n; i++)
System.out.println("Participant " + (i + 1) + " = " + score[i]);
System.out.println("Highest score(s):");
for(int i = 0; i < n; i++)
if(score[i] == highest)
System.out.println("Participant " + (i + 1));
}
}``````