Answered! Java programming First, create a method to grade the student exams – gradeExams(). It takes 2 parameters: the answer key (single…

Java programming

First, create a method to grade the student exams – gradeExams(). It takes 2 parameters: the answer key (single dimensional array) and the student answers (two dimensional array); displays the results; no return value (void). It should invoke a second method – gradeExam() that takes 2 parameters: the answer key (single dimensional array) and a single dimensional array for a single student’s answers; displays the results; no return value (void).

Once this works, create 2 more methods: getAnswerKey() and getStudentAnswers() which prompt the user for the corresponding information. getAnswerKey() returns a single dimensional array and getStudentAnswers() returns a two dimensional array. Note: getStudentAnswers() should take a single parameter specifying the number of questions (you can determine the value by looking at the array returned by getAnswerKey() ) – use this value to check that the user entered the correct number of answers for each student. Use your gradeExams() method to grade the user-supplied info.

Expert Answer

Below is your program: –

Assignment.java

import java.util.Scanner;

public class Assignment {
static int count = 0;
public static void main(String[] args) {
char[] answerKey = getAnswerKey();
char[][] studentAnswers = getStudentAnswers(answerKey.length);
gradeExams(answerKey, studentAnswers);
System.exit(0);
}

private static char[] getAnswerKey() {
Scanner scanner = new Scanner(System.in);
// Prompts user to input answer key
System.out.println(“Enter the answer key: “);
String answerKey = scanner.nextLine();
// Returns answer key as an array
return answerKey.toCharArray();
}

private static char[][] getStudentAnswers(int numOfQuestions) {
Scanner scanner = new Scanner(System.in);
// Prompts user to input number of students
System.out.println(“Enter number of students: “);
int numOfStudents = Integer.parseInt(scanner.nextLine());
// Creates multidimensional array for student answers
char[][] studentAnswers = new char[numOfStudents][numOfQuestions];

// Prompts user to input students’ answers
for (int j = 0; j < numOfStudents; j++) {
System.out.println(“Enter student ” + (j + 1) + “‘s answers: “);
String answers = scanner.nextLine();
studentAnswers[j] = answers.toCharArray();
}
return studentAnswers;
}

private static void gradeExams(char[] answerKey, char[][] studentAnswers) {
// Calculations for grading each students’ exams
for (int i = 0; i < studentAnswers.length; i++) {
count++;
gradeExams(answerKey, studentAnswers[i]);
}
}

private static void gradeExams(char[] answerKey, char[] studentAnswers) {
// Calculations for grading one student’s exams
int correctCount = 0;
for (int i = 0; i < answerKey.length; i++) {
if (studentAnswers[i] == answerKey[i])
correctCount++;
}
System.out.println(“For the student “+count +” correct count is ” + correctCount + “.”);
}
}

Sample Run:-

Enter the answer key:
AABBCC
Enter number of students:
4
Enter student 1’s answers:
ACBACB
Enter student 2’s answers:
ABABAB
Enter student 3’s answers:
ACACAC
Enter student 4’s answers:
CBCBCB
For the student 1 correct count is 3.
For the student 2 correct count is 2.
For the student 3 correct count is 2.
For the student 4 correct count is 2.

Still stressed from student homework?
Get quality assistance from academic writers!