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

The local Drivers licencse office has asked you to write a program that grades t

ID: 3771524 • Letter: T

Question

The local Drivers licencse office has asked you to write a program that grades the written portion of the drivers license exam. The exam has 20 multiple choice questions. Here are the correct answeres:

1. B 6. A 11. B 16. C

2. D 7.B 12. C 17.C

3. A 8. A 13. D 18. B

4. A 9. C 14. A 19. D

5. C 10. D 15. D 20. A

Write a PROGRAM 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. The PROGRAM should do the following. NO CLASSES(or methods).

Determine and display if the student "passed" or " failed" the exam.

Determine and display the total number of correctly answered questions

Determine and display the total of incorrectly answered questions

Determine and display the question numbers that the student missed.

Test for invalid inputs.

Explanation / Answer

import java.io.*;

public class DriverExam{
         public static void main(String []args) throws IOException
     {
      BufferedReader br = new
      BufferedReader(new InputStreamReader(System.in));
      //char correctanswers=new char[20];
      char[] studentanswers=new char[20];
      char[] correctanswers={'B','D','A','A','C','A','B','A','C','D','B','C','D','A','D','C','C','B','D','A'};
        System.out.println("enter student answers of the given 20 questions");
System.out.println("enter '* 'for unknown answers");

for(int i=0;i<20;i++){
     char ch= (char) br.read();
     if(Character.isLetter(ch)||ch=='*')// accepting valid inputs and to identity unanswered questions
     studentanswers[i]=ch;
     else //test for invalid input
     {
         System.out.println("invalid input");
         return;
     }
}

// to find correctly answered questions
int sumcorrect=0;
for(int i=0;i<20;i++)
{
     if(correctanswers[i]==studentanswers[i])
     sumcorrect++;
     else
     continue;
}
//to find incorrect answers
int sumincorrect=0;
for(int i=0;i<20;i++)
{
     if(correctanswers[i]!=studentanswers[i]&&studentanswers[i]!='*')//exclude unanswered questions
     sumincorrect++;
     else
     continue;
}
// to find unanswered questions

int sumunanswered=0;
for(int i=0;i<20;i++)
{
     if(studentanswers[i]=='*')//exclude unanswered questions
     sumunanswered++;
     else
     continue;
}
//TO FIND WHETHER STUDENT PASSED OR FAIL
if(sumcorrect>=9)
System.out.println("student passed test");
else
System.out.println("student failed test");
System.out.println(" number of correct answers"+ sumcorrect);
System.out.println(" number of INcorrect answers"+ sumincorrect);
System.out.println(" number of UNanswerd"+ sumunanswered);

     }
}