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 drivers\' license exam. The exam

ID: 3869018 • Letter: W

Question

Write a program that grades the multiple choice drivers' license exam. The exam has the following answer key: 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 The program will input a person's answers and display the percent correct along with a message whether they passed or failed the test. Use the following methods: public static void getExamData (char responses []) that will let the user input the 20 values public static boolean passed (int numcorrect) that returns true if they answer at least 15 out of the 20 correctly. public static int totalCorrect (char responses []) returns the number of correct answers using an array containing the answer key

Explanation / Answer

DriversLicenceExam.java

import java.util.Scanner;

public class DriversLicenceExam {

public static void main(String[] args) {

// Declaring variables
int numCorrect = 0;

System.out.println("20 Multiple choice questions ");

// Creating the array of type String
char[] responses = new char[20];

// Calling the method
getExamData(responses);

// Calling the method
numCorrect = totalCorrect(responses);

// Based on the boolean value display th message
if (passed(numCorrect)) {
System.out.println("Percentage of Correct Answers :" + ((double) numCorrect / responses.length) * 100);
System.out.println("** You Passed in the Exam**");
} else {
System.out.println("Percentage of Correct Answers :" + ((double) numCorrect / responses.length) * 100);
System.out.println("** You Failed in the Exam**");
}

}

// This method will return a boolean value based on number of correct
// answers
private static boolean passed(int numCorrect) {
if (numCorrect >= 15)
return true;
else
return false;
}

// This method will return the no of correct answers
private static int totalCorrect(char[] responses) {
int correct = 0;

// an array of student's answers.
final char[] correctAnswers = {
'B',
'D',
'A',
'A',
'C',
'A',
'B',
'A',
'C',
'D',
'B',
'C',
'D',
'A',
'D',
'C',
'C',
'B',
'D',
'A'
};

for (int i = 0; i < responses.length; i++) {
if (responses[i] == correctAnswers[i]) {
correct++;
}
}
return correct;
}

/*
* This method will get the answers entered by the user and populate those
* values into an array
*/
private static void getExamData(char[] responses) {
// scanner class object is used to read the inputs entered by the user
Scanner kb = new Scanner(System.in);

for (int i = 0; i < responses.length; i++) {

System.out.print("Enter Answer :" + (i + 1) + ":");
responses[i] = kb.next(".").charAt(0);

}

}

}

_______________________

output:

20 Multiple choice questions
Enter Answer :1:B
Enter Answer :2:D
Enter Answer :3:A
Enter Answer :4:A
Enter Answer :5:C
Enter Answer :6:A
Enter Answer :7:B
Enter Answer :8:A
Enter Answer :9:C
Enter Answer :10:D
Enter Answer :11:B
Enter Answer :12:C
Enter Answer :13:D
Enter Answer :14:A
Enter Answer :15:B
Enter Answer :16:C
Enter Answer :17:A
Enter Answer :18:B
Enter Answer :19:D
Enter Answer :20:C
Percentage of Correct Answers :85.0
** You Passed in the Exam**


_____________Could you rate me well.Plz .Thank You

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