JAVA The local Drivers License Office has asked you to write

JAVA

The local Driver\'s License Office has asked you to write a program that grades the written portion of the license exam. The exam has 20 multiple choice questions. Here are the correct answers:

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

Write a class named DriverExam that holds the correct answers to the exam in an array field. The class should have an array field to hold the student\'s answers. The class should have the following methods:

passed. The method returns true if the student passed the exam, false otherwise

totalCorrect: returns the total number of correctly answered questions

totalIncorrect: returns the total number of incorrectly answered questions

questionsMissed: an int array containing the question numbers of the question that the student missed

Demonstrate the class in a test program that asks the user to enter a student\'s answers, and then display the results returned from the DriverExam class\'s methods.

Input validation: only accept the letters A, B, C, or D as answers

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

Solution

please let me know if you need more information:-

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

DriverExam.java

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

import java.util.Scanner;

public class DriverExam {
   private char Answers[] = { \'A\', \'B\', \'A\', \'B\', \'A\', \'B\', \'A\', \'B\', \'A\', \'B\', \'A\',
           \'B\', \'A\', \'B\', \'A\', \'B\', \'A\', \'B\', \'A\', \'B\' };//Sample answaers fixed please copy accordingly.

   public boolean passed(char arr[]) {
       //15 questions of the 20
       int correct = 0;
       boolean passed = true;
       boolean fail = false;
       for (int i = 0; i < Answers.length; i++) {
           if (Answers[i] == arr[i])
               correct++;
       }
       if(correct >= 15) return passed;
       else return fail;
   }

   public int totalCorrect(char arr[]) {
       int correct = 0;
       for (int i = 0; i < Answers.length; i++) {
           if (Answers[i] == arr[i])
               correct++;
       }
       return correct;
   }

   public int totalIncorrect(char arr[]) {
       int inCorrect = 0;
       for (int i = 0; i < Answers.length; i++) {
           if (Answers[i] != arr[i])
               inCorrect++;
       }
       return inCorrect;
   }

   public int questionsMissed(char arr[]) {
       int missed = 0;
       for (int i = 0; i < Answers.length; i++) {
           if (Answers[i] != \'\\0\')
               missed++;
       }
       return missed;
   }


}

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

TestExamResult.java

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

import java.util.Scanner;


public class TestExamResult {
  
   public static void main(String[] args) {
       // TODO Auto-generated method stub
       char Answers[] = new char[20];
       DriverExam de = new DriverExam();
       Scanner sc = new Scanner(System.in);
       System.out.println(\"Anter Answers ANY ONE OF [A,B,C,D]\");
       for (int i = 0; i < 20; i++) {
           System.out.println(\"Enter \"+ i +\" Answer ..\");
           String input = sc.next();
           if(input !=null && (input.charAt(0) == \'A\' ||input.charAt(0) == \'B\'||input.charAt(0) == \'B\'||input.charAt(0) == \'C\')){
               Answers[i] = input.charAt(0);
           }
           else{
               System.out.println(\"Invalid input.. taking it as no answer\");
           }
       }
       boolean status = de.passed(Answers);
       int missed = de.questionsMissed(Answers);
       int answered = de.totalCorrect(Answers);
       int incorrect = de.totalIncorrect(Answers);
       System.out.println(\"Student :\" + status);
       System.out.println(\"Missed : \"+missed);
       System.out.println(\"Answered : \"+answered);
       System.out.println(\"Incorrect : \"+incorrect);
      
   }
}

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

Thanks

JAVA The local Driver\'s License Office has asked you to write a program that grades the written portion of the license exam. The exam has 20 multiple choice qu
JAVA The local Driver\'s License Office has asked you to write a program that grades the written portion of the license exam. The exam has 20 multiple choice qu
JAVA The local Driver\'s License Office has asked you to write a program that grades the written portion of the license exam. The exam has 20 multiple choice qu

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site