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

rewrite this code GradeExam.java, to display the students in increasing order of

ID: 3626841 • Letter: R

Question

rewrite this code GradeExam.java, to display the students in increasing order of the number of correct answers.

public class GradeExam {

/** Main method */

public static void main(String args[]) {

// Students' answers to the questions
char[][] answers = {

{'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'}};



// Key to the questions
char[] keys = {'D', 'B', 'D', 'C', 'C', 'D', 'A', 'E', 'A', 'D'};



// Grade all answers
for (int i = 0; i < answers.length; i++) {

// Grade one student
int correctCount = 0;

for (int j = 0; j < answers[i].length; j++) {

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

correctCount++;

}



System.out.println("Student " + i + "'s correct count is " +

correctCount);

}

}

}

Explanation / Answer

please rate - thanks

public class GradeExam {
/** Main method */
public static void main(String args[]) {
// Students' answers to the questions
char[][] answers = {
{'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'}};
// Key to the questions
char[] keys = {'D', 'B', 'D', 'C', 'C', 'D', 'A', 'E', 'A', 'D'};
int []order=new int[answers.length];
int []correctCount=new int[answers.length];
int t;
for(int i=0;i<answers.length;i++)
     order[i]=i;
// Grade all answers
for (int i = 0; i < answers.length; i++) {
// Grade one student
correctCount[i] = 0;
for (int j = 0; j < answers[i].length; j++) {

if (answers[i][j] == keys[j])
correctCount[i]++;
}

}


for(int i=0;i<answers.length-1;i++)
    for(int j=i;j<answers.length;j++)
        if(correctCount[i]>correctCount[j])
             {t=correctCount[i];
            correctCount[i]=correctCount[j];
            correctCount[j]=t;
            t=order[i];
            order[i]=order[j];
            order[j]=t;
            }
for(int i=0;i<answers.length;i++)
System.out.println("Student " + order[i] + "'s correct count is " +correctCount[i]);

}}