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

Write a program named GradeQuiz.java that grades multiple-choice quizzes as foll

ID: 3673952 • Letter: W

Question

Write a program named GradeQuiz.java that grades multiple-choice quizzes as follows:

1.Ask the user how many questions are in the quiz.

2. Ask the user to enter the key (that is, the correct answers). There should be one answer for each question in the quiz, and each answer should be a lower-case letter. You will need to store the key in an array.

3. Ask the user to enter the actual answers for the quiz to be graded. Again there needs to be one for each question. Note that these answers do not need to be stored; each answer can simply be compared to the key as it is entered.

4. When the user has entered all of the answers to be graded, print the number correct and the percent correct.

5. When this works, add a loop so that the user can grade any number of quizzes with a single key. After the results have been printed for each quiz, ask "Grade another quiz? (y/n)."

Explanation / Answer

import java.util.Scanner;

public class GradeQuiz {
  
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       char c;
       int n;
       do{
           System.out.println("How many questions are in Quiz: ");
           n = sc.nextInt(); // number of questions
           //array to store correct key
           String grade[] = new String[n];
           for(int i=0; i<n;i++){// filling array with correct key
               System.out.print("Enter correct key for Q"+(i+1)+":");
               grade[i] = sc.next();
           }
           int correct = 0; // number of correct answer
           //checking each quiz key against correct key
           for(int i=0; i<n; i++){
               System.out.print("Enter quiz key for Q"+(i+1)+":");
               String quizKey = sc.next();
               if(grade[i].equalsIgnoreCase(quizKey)) // if quiz key matches against correct key
                   correct ++;
           }
          
           System.out.println("Number of correct answer: "+correct);
           System.out.println("Percentage of correct answer: "+(((double)correct/n)*100));
          
           System.out.println("Grade another quiz?(y/n)");
           c = sc.next().charAt(0);
       }while(c=='y');
       sc.close();
   }

}

/*

Output:

How many questions are in Quiz:
5
Enter correct key for Q1:abc
Enter correct key for Q2:qwe
Enter correct key for Q3:rat
Enter correct key for Q4:klm
Enter correct key for Q5:apple
Enter quiz key for Q1:qwe
Enter quiz key for Q2:qwe
Enter quiz key for Q3:rat
Enter quiz key for Q4:mnb
Enter quiz key for Q5:apple
Number of correct answer: 3
Percentage of correct answer: 60.0
Grade another quiz?(y/n)
n

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote