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

Multi-Dimensional Array Write a program that grades multiple choice question of

ID: 3739771 • Letter: M

Question

Multi-Dimensional Array

Write a program that grades multiple choice question of 10 students with reference to the key. In addition, you have to sort the students (student 0-9) based on the scores. The program can be user interaction prompt for entering the answers for 10 students.

Hint: Refer slide 21 and 88 (savitch)



The first slide is slide 21, the second slide is slide 88

n vinuses Unless you need to edit, ies sater to stay in Puotected Enable Ediing but first we need to close some apps. Pitfall: Arrays with a Class Base Type The base type of an array can be a class type Date[1 holidayList -new Date [201: . The above example creates 20 indexed variables of type Date It does not create 20 objects of the class Date Each of these indexed variables are automatically initialized to null Any attempt to reference any them at this point would result in a "null pointer exception" error message

Explanation / Answer

The code would be

import java.util.Arrays;

import java.util.Scanner;

public class Billing

{

static int[] key= {1,1,2,3,4,2,4,1,3,2};//key is the solution key 1 for a 2 for b 3 for c 4 for d

static int[][] answers=new int[10][10];

static int[] score=new int[10];

public static void main(String[] args)

{

Scanner in =new Scanner(System.in);

for(int i=0;i<10;i++)

{

System.out.println("Enter Answers of Student "+i+1);

for(int j=0;j<10;j++)

{

System.out.println("Enter Ans for Question "+j+1);

answers[i][j]=in.nextInt();

if(key[j]==answers[i][j])

score[i]++;

}

}

Arrays.sort(score);

for(int i=0;i<10;i++)

System.out.println(score[i]);

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote