Grading a Multiple-Choice Test in Java

Problem:

The problem is to write a program that grades multiple-choice tests. Suppose there are eight students and ten questions, and the answers are stored in a two-dimensional array. Each row records a student’s answers to the questions, as shown in the following array.

The key is stored in a one-dimensional array:
Key to the Questions: 0 1  2  3  4  5  6 7 8 9
                                 D B D C C D A E A D

Your program grades the test and displays the result. It compares each student’s answers with
the key, counts the number of correct answers, and displays it.


Output:



Solution:

import java.util.Scanner;

public class twoDimentionalArrays
{
  
public static void main (String[] args)
{
  Scanner scan = new Scanner (System.in);
  String[] answers = { "D","B","D","C","C","D","A","E","A","D"};
  String[][] list = new String[8][10];
  System.out.println("Fill in the eight student's answers to 10 questions" );
  for (int i =0;i<list.length;i++)
  {
    int count =0;
    for (int j=0;j<list[i].length;j++)
    {
      list[i][j] = scan.next();
      if(list[i][j].equalsIgnoreCase(answers[j]))
        count++;
    }
    System.out.println("Student's " + i + " correct answers are " + count);
  }
  
}
}


4 comments :

  1. Hello,
    I was wondering if you could direct me to the library you used for this.

    ReplyDelete
    Replies
    1. Hello! No external libraries were used for this program. The library used in this program is found by default in Java. It is called the "Scanner" library. You can import it in any Java program without having to add any dependencies.

      Information about the library can be found here: https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html

      --
      George

      Delete
  2. Can i get this code in c language?

    ReplyDelete

Follow Me

If you like our content, feel free to follow me to stay updated.

Subscribe

Enter your email address:

We hate spam as much as you do.

Upload Material

Got an exam, project, tutorial video, exercise, solutions, unsolved problem, question, solution manual? We are open to any coding material. Why not upload?

Upload

Copyright © 2012 - 2014 Java Problems  --  About  --  Attribution  --  Privacy Policy  --  Terms of Use  --  Contact