(Sorting students on grades) Rewrite listing 7.2, GradeExam.java, to display stu
ID: 3641359 • Letter: #
Question
(Sorting students on grades) Rewrite listing 7.2, GradeExam.java, to display students in increasing order of the number of correct answers.public class GradeExam {
// main methord
//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 < answer[i].;ength; j++) {
if (answers[i][j] == keys[j])
correctCount++
}
System.out.println("Stundent " + i + "'s correct count is " + correctCount);
}
}
}
Explanation / Answer
Please rate...
public class GradeExam {
// main methord
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'},};
int cc[]=new int[answers.length];
int cn[]={1,2,3,4,5,6,7,8};
int i,j,t;
//KEY TO THE QUESTIONS
char[] keys = {'D', 'B', 'D', 'C', 'C', 'D', 'A', 'E', 'A', 'D'};
//GRADE ALL ANSWERS
for (i = 0; i < answers.length; i++) {
//Grade one student
int correctCount = 0;
for(j = 0; j < answers[i].length; j++) {
if (answers[i][j] == keys[j])
correctCount++;
}
cc[i]=correctCount;
}
for (i = 0; i < answers.length; i++)
{
for(j=0;j<(answers.length-1);j++)
{
if(cc[j]>cc[j+1])
{
t=cc[j];
cc[j]=cc[j+1];
cc[j+1]=t;
t=cn[j];
cn[j]=cn[j+1];
cn[j+1] =t;
}
}
}
for (i = 0; i < answers.length; i++)
{
System.out.println("Student " + cn[i] + "'s correct count is " + cc[i]);
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.