import javax.swing.JOptionPane;
public class GradeExam {
public static void main(String[] args) {
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'}};
char[] keys = {'D', 'B', 'D', 'C', 'C', 'D', 'A', 'E', 'A', 'D'};
//Create new array to sort students
int[] student = new int[8];
//Echo the answers
String result = "The answer key to the test: \n";
for (int k = 0; k < 10; k++) {
result += keys[k] + " ";
}
for (int i = 0; i < answers.length; i++) {
int correctCount = 0;
//Convert grades to a String
String result2 = "Student " + (i + 1) + "'s answers are: \n";
for (int j = 0; j < answers[i].length; j++) {
result2 += answers[i][j] + " ";
if (answers[i][j] == keys[j])
correctCount++;
student[i] = correctCount;
}
//Display the input
JOptionPane.showMessageDialog(null, result + "\n" + result2 +
"\nStudent " + (i + 1) + "'s correct count is " + correctCount);
}
//Find the maximum in the list
for (int i = student.length - 1; i > 0; i--) {
int currentMax = student[i];
int currentMaxIndex = i;
for (int j = i - 1; j > (-1); j--) {
if (currentMax < student[j]) {
currentMax = student[j];
currentMaxIndex = j;
}
}
//Swap student[i] with list[currentMinIndex] if necessary
if (currentMaxIndex != i) {
student[currentMaxIndex] = student[i];
student[i] = currentMax;
}
}
//Convert input to a String
String result3 = "The students sorted scores: \n" + "\n";
for (int i = 0; i < student.length; i++) {
result3 += "Student " + (i + 1) + "'s score = " + student[i] + " \n";
}
//Display the sorted grades
JOptionPane.showMessageDialog(null, result3);
JOptionPane.showMessageDialog(null, "Thanks for playing!");
}
}