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

Write a program that grades the multiple-choice answers for a 20-question exam.

ID: 3788320 • Letter: W

Question

Write a program that grades the multiple-choice answers for a 20-question exam. A student must answer at least 15 out of 20 of the questions correctly to pass the exam. Use a class named DriverExam that holds the correct answers to the exam in an array field. The class should also have an array field that holds the student's answers.

// Array containing the correct answers private char[] correctAnswers = {'B','D','A','A','C','A','B','A','C','D','B','C','D','A','D','C','C','B','D','A'};

// All student's answers private char[] [] Answers; Each row is a student

The DriverExam constructor method accepts a char array parameter argument containing the 20 student answers. In addition, the class should have the following methods (as shown by the traditional UML class diagram)

- correctAnswers : char[] = {'B','D'...

- studentAnswers : char[]

+ DriverExam (s : char[])

+ totalCorrect() : int

+ totalInCorrect() : int

+ passed() : boolean

+ questionsMissed(): int[]

ALMOST Duplicate this class interface exactly. – Need a method to extract a row to process and a private char[] [] Answers;

passed - returns true if the student passed the exam or false if the student failed totalCorrect

- Returns the total number of correctly answered questions totalIncorrect

- Returns the total number of incorrectly answered questions questionsMissed

- Returns an int array containing the question #’s that the student missed & Return null if the student answered all questions correctly.

Demonstrate the class in a main method that asks the user to enter attempted answers for 4 students (results in Unit Test box), and then displays the results returned from the DriverExam class's methods.

Unit Testing for 1

Sample Session

Write a main method in ExamDemo.java that allows a user to enter as many as desired (a loop) 20 multiplechoice answers, stores them in the 2 dimensional array studentAnswers [] [] and then calls your DriverExam methods to determine the number correct, incorrect, whether the user passed or not, and the numbers of the questions that each user answered incorrectly for each row of the 2 dimensional array – i.e., use a loop and pass each row (a student) to be processed.

Input Validation: Only accept the letters A, B, C, or D as answers

-- NOTE: -- NO REAL Legend shown in this sample for a single row od data.

------------------------------------------

------------------------------------------

Programming Style Requirements

What to turn in

1. Your project will be graded directly in NetBeans.

2. Be sure your project is saved in a last-name-H2 folder -- Zip the folder & upload via course web (include Test snips)

3. Unit Tests

Extra Credit – Make a copy of this Program – call it program 2a – modify the input method to read from a file instead of the keyboard. Submit the modified package & data input file in a separate zip file.

char CJ userAnswers ('B', 'D', 'A', 'A', 'C', 'A', 'B', 'A', 'C', 'D', 'B', 'C', 'D', 'A', 'D', 'C', 'C', 'A', D', 'C' Driver Exam e new DriverExam (userAnswers e passed true e total Correct 18 e total Incorrect questions Missed [I ce908 questions Missed [0] e questions Missed [1] 20 Note: unit testing the questionsMissed0method is a little tricky as it returns an array of integers. You can use a subscript to display individual elements of the returned array. For example, to examine the first question missed (at subscript [0]) you would call e.questionsMissed [01

Explanation / Answer

1)

import java.util.ArrayList;

public class DriverExam {

   int totalCorrectAnswercount;
   private char[] correctAnswers = { 'B', 'D', 'A', 'A', 'C', 'A', 'B', 'A',
           'C', 'D', 'B', 'C', 'D', 'A', 'D', 'C', 'C', 'B', 'D', 'A' };
   private char[] studentAnswers;

   public DriverExam(char[] studentAnswers) {
       this.studentAnswers = studentAnswers;
   }

   int totalCorrect() {
       int count = 0;
       for (int i = 0; i < correctAnswers.length; i++) {
           for (int j = 0; j < studentAnswers.length; j++) {
               if (i == j) {
                   if (correctAnswers[i] == studentAnswers[j]) {
                       count++;
                   }
               }

           }
       }

       return count;

   }

   int totalInCorrect() {
       int count = 0;
       int totalcount = 20;
       for (int i = 0; i < correctAnswers.length; i++) {
           for (int j = 0; j < studentAnswers.length; j++) {
               if (i == j) {
                   if (correctAnswers[i] == studentAnswers[j]) {
                       count++;
                   }
               }

           }
       }

       return totalcount - count;

   }

   boolean passed() {
       if (totalCorrectAnswercount >= 15) {
           return true;
       }
       return false;

   }

   Object[] questionsMissed() {
       ArrayList<Integer> list = new ArrayList<Integer>();
       for (int i = 0; i < studentAnswers.length; i++) {
           if (studentAnswers[i] == 'u0000' || studentAnswers[i] == 0) {
               list.add(i+1);
           }
       }

       Object[] array = list.toArray();
       return array;

   }

   public static void main(String[] args) {
       char[] userAnswers = { 'B', 'D', 'A', 'A', 'C', 'A', 'B', 'A', 'C',
               'D', 'B', 'C', 'D', 'A', 'D', 'C', 'C', 'A', 'D', 'C' };
       DriverExam exam = new DriverExam(userAnswers);
       exam.totalCorrectAnswercount = exam.totalCorrect();
       System.out.println("the total correct answers are "
               + exam.totalCorrectAnswercount);
       int totalIncorrect = exam.totalInCorrect();
       System.out
               .println("the total incorrect answers are " + totalIncorrect);
       boolean flag = exam.passed();
       if (flag) {
           System.out.println(" the student passed");
       } else
           System.out.println("the student failed");

       Object[] array = exam.questionsMissed();
       if (array.length == 0) {
           System.out.println("the missed questions are zero");
       } else {
           for (Object o : array) {

               System.out.println("the missed question no's are " + (int) o);
           }
       }
   }

}

output

the total correct answers are 18
the total incorrect answers are 2
the student passed
the missed questions are zero

sample run 2

if we pass student answers in main program like this the output is:

char[] userAnswers = { 'B', 'D', 'A', 0, 'C', 'A', 'B', 'A', 'C', 'D', 'B', 'C', 'D', 'A', 0, 'C', 0, 'A', 'D', 'C' };

the total correct answers are 15
the total incorrect answers are 5
the student passed
the missed question no's are 4
the missed question no's are 15
the missed question no's are 17

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