Java Problem: Grading a Multiple-Choice Test and Sorting The Results


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, sort grades in increasing order by keeping 
student's number.

Output:


import java.util.Scanner;

public class twoDimentionalArrays
{
  public static void main (String[] args)
  {
    Scanner scan = new Scanner (System.in);
    String[] key = "D" "B" "D" "C" "C" "D" 
        "A" "E" "A" "D" };
    System.out.println("Fill in the eight student's ans" +
        "wers to 10 questions");
    String[][] list = new String[8][10];
    int[][] sort = new int[8][1];
    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(key[j]))
        {  count++;
          sort[i][0= count;
        }
        
      }
    }
  int[] students = ,,,,,,67};
  for (int i =0;i<sort.length;i++)
    {
      for (int j=0;j<sort.length-1;j++)
      {
        if (sort[j][0> sort[j+1][0])
        {
          int temp = sort[j][0];          
          sort[j][0= sort[j+1][0];
          sort[j+1][0= temp;
          
          int temp2 = students[j];
          students[j= students[j+1];
          students[j+1]= temp2;
        }
      }
    
    for (int i =0;i<sort.length;i++)
    {
      System.out.println("Student "+ students[i]+" score per order " + sort[i][0]);
    }
    
  }
}


No comments :

Post a Comment

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