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

JAVA BEGINNER PROGRAMMING Your instructor has asked you to write a program that

ID: 3677847 • Letter: J

Question

JAVA BEGINNER PROGRAMMING

Your instructor has asked you to write a program that grades an exam. The exam has 15 multiple choice questions. Here are the correct answers:

    1. B
    2. D
    3. A
    4. A
    5. C
    6. D
    7. A
    8. B
    9. C
    10. A
    11. B
    12. C
    13. D
    14. A
    15. B

A student must correctly answer 12 out of the 15 questions to pass the exam.

Write a program that holds the correct answers to the exam in an array. The program should have an array that hold's the student's answers. The program should have the following static methods:
a. passed() returns true if the student passed the exam or false if the student failed.
b. totalCorrect() - Return the total number of correctly answered questions.
c. totalIncorrect() - Returns the total number of incorrectly answered questions.
d. An int array containing the questions numbers of the questions that the student missed.

Demonstrate the program by setting the values of student's answers in main(You are not required to prompt the user to enter values using Scanner or System.in.read()), and then display the result returned from the methods written in the program.

Here are some suggestions on variable and method declarations.
    char [] coorectAns = new char[15];
    char [] studentAns = new char[15];

static boolean passed(char [] correct, char [] student) { }
static int totalCorrectAnswers(char [] correct, char [] student) { }
static int totalInCorrectAnswers(char [] correct, char [] student) { }
static int [] questionNumbersMissed(char [] correct, char [] student) {
    //which questions were either not answered or were incorrect.
    //declaring a char array that keeps track of the questions that were incorrectly answered.
    //example - reverse method in PDF.
}

Explanation / Answer

import java.util.Scanner;

public class Exam {

   static boolean passed(char [] correct, char [] student) {
       int correctAns = 0;
       for(int i=0; i< 15; i++){
           if(correct[i] == student[i])
               correctAns++;
       }
       return correctAns >= 12;
   }
   static int totalCorrectAnswers(char [] correct, char [] student) {
       int correctAns = 0;
       for(int i=0; i< 15; i++){
           if(correct[i] == student[i])
               correctAns++;
       }
       return correctAns;
   }
   static int totalInCorrectAnswers(char [] correct, char [] student) {
       int inCorrectAns = 0;
       for(int i=0; i< 15; i++){
           if((student[i] == '') && (correct[i] != student[i]))
                   inCorrectAns++;
       }
       return inCorrectAns;
   }
   static int[] questionNumbersMissed(char [] correct, char [] student) {
       int numberOfMissed = totalCorrectAnswers(correct, student)-totalInCorrectAnswers(correct, student);
       int []missed = new int[numberOfMissed];
       int k=0;
       for(int i=0; i< 15; i++){
           if(student[i] == '')
               missed[k++] = (i+1); // (i+1) is question number
       }
       return missed;
   }
  
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
      
       char [] coorectAns = {'B','D','A','A','C','D','A','B','C','A','B','C','D','A','B'};
       char [] studentAns = new char[15];
       for(int i=0; i<15; i++){
           System.out.print("Enter answer for "+(i+1)+" question: ");
           studentAns[i] = sc.next().charAt(0);
       }
      
   }
}