Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

USE THE ABOVE CODE IN YOURS ANSER ( ANY ONE OF 2) THERE SHOULD BE NO INPUT NEEDE

ID: 3846185 • Letter: U

Question

USE THE ABOVE CODE IN YOURS ANSER ( ANY ONE OF 2) THERE SHOULD BE NO INPUT NEEDED

This assignment is the first in-class assignment dealing with single- and multi-dimensional arrays, specifically, to grade student exams using a single-dimensional array to hold the answer key and a multi-dimensional array to hold the students' answers. You need to complete this assignment prior to doing part 2. For today: Create a class to grade student responses to a multiple choice test. You will create a single-dimensional array for the answer key and a multi (two)-dimensional array to hold the students' answers For simplicity, make the answer key a charll and the student answers a charlJU. To instantiate and initialize them, use the curly brace notation. [See the sample code fragments to save some typing.] The data for the answer key is: Question number (index) 0 1 2 3 4 5 6 7 8 9 Correct answer D B D C C D A E A D The data for the student answers is: 0 1 2 3 4 5 6 7 89 Question number (index) Student A B A C C D E E A D Student 1 D B A B C A E E A D Student 2 E D D A C B E E A D Student 3 C B A E D C E E A D Student 4 A B D C C D E E A D Student 5 B B E C C D E E A D Student 6 B B A C C D E E A D Student 7 E B E C C D E E A D Your program should not do any input/prompting. The output is mostly up to you but it should reflect each student's grade, the success rate for each question or both. Remember: Use mnemonic variable names even for loop variables You may create utility methods but it is not required. No error checking is required all data is valid

Explanation / Answer

Code:
public class GradeStudent{
// Program to display number of correct and incorrect answers
public static void main(String []args){
char[] answerKeyFromChars = { 'D', 'B', 'D', 'C', 'C', 'D', 'A', 'E', 'A', 'D' } ;
char[][] studentsAnswersFromChars =
{ { 'A', 'B', 'A', 'C', 'C', 'D', 'E', 'E', 'A', 'D' },
{ 'D', 'B', 'A', 'B', 'C', 'A', 'E', 'E', 'A', 'D' },
{ 'E', 'D', 'D', 'A', 'C', 'B', 'E', 'E', 'A', 'D' },
{ 'C', 'B', 'A', 'E', 'D', 'C', 'E', 'E', 'A', 'D' },
{ 'A', 'B', 'D', 'C', 'C', 'D', 'E', 'E', 'A', 'D' },
{ 'B', 'B', 'E', 'C', 'C', 'D', 'E', 'E', 'A', 'D' },
{ 'B', 'B', 'A', 'C', 'C', 'D', 'E', 'E', 'A', 'D' },
{ 'E', 'B', 'E', 'C', 'C', 'D', 'E', 'E', 'A', 'D' }
} ;
int[][] studentResult= new int[8][2];
  
// initializing studentResult 2d array to zero where 0th location represents number of correct answers and 1st location represents number of incorrect answers
for(int i = 0; i < studentResult.length; i++)
studentResult[i][0]= studentResult[i][1] = 0;

   // Iterating through student 2D array
   for(int i = 0; i < studentsAnswersFromChars.length; i++ ){
   for(int j = 0; j < studentsAnswersFromChars[i].length; j++){
   // checking student answers with key
   if(studentsAnswersFromChars[i][j] == answerKeyFromChars[j])
   studentResult[i][0]++;
   else
   studentResult[i][1]++;
   }
   }

   // displaying student results
   System.out.println("Student Results are:");
   for(int i = 0; i < studentResult.length; i++){
   System.out.println("Student "+ i +" has "+ studentResult[i][0] +" correct "+"and "+ studentResult[i][1] + " wrong answers" );
   }

   }
}

Execution and output:
sh-4.3$ java GradeStudent
Student Results are:
Student 0 has 7 correct and 3 wrong answers   
Student 1 has 6 correct and 4 wrong answers   
Student 2 has 5 correct and 5 wrong answers   
Student 3 has 4 correct and 6 wrong answers   
Student 4 has 8 correct and 2 wrong answers   
Student 5 has 7 correct and 3 wrong answers   
Student 6 has 7 correct and 3 wrong answers   
Student 7 has 7 correct and 3 wrong answers