Question

Java: The local Driver's License Office has asked you to write a program that grades the...

Java: The local Driver's License Office has asked you to write a program that grades the written portion of the driver's
  license exam. The exam has 20 multiple choice questions.
  Here are the correct answers:
   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
  
Your program should store the correct answers in an array. (Store each question's answer in an element of a String array.) The program should ask the user to enter the student's answers for each of the 20 questions, which should be stored in another array. After the student's answers have been entered, the program should display a message indicating whether the student passed or failed. A student must correctly answer 15/20 to pass. It should then display the total number of correctly answered questios, the total number of incorrectly answered, and a list showing the question numbers of incorrectly answered questions.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class MCQChecker {
  
public static void main(String[] args)throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] correctAnswers = {"B", "D", "A", "A", "C", "A", "B", "A", "C", "D", "B", "C", "D", "A", "D",
"C", "C", "B", "D", "A"};
String[] studentAnswers = new String[20];
String userIn = "";
int counterForCorrectAnswers = 0;
  
// prompt user to enter answers to 20 questions
System.out.println("You must enter either of the options A, B, C or D for each of the questions.");
for(int i = 0; i < 20; i++)
{
do
{
System.out.print("Enter answer for question #" + (i + 1) + "[A/B/C/D]: ");
userIn = br.readLine();
if(userIn.length() == 1 && (userIn.equalsIgnoreCase("A") || userIn.equalsIgnoreCase("B")
|| userIn.equalsIgnoreCase("C") || userIn.equalsIgnoreCase("D")))
break;
else
System.out.println("\nPlease enter either of the options: A, B, C or D!");
  
}while(userIn.length() > 1 || !userIn.equalsIgnoreCase("A") || !userIn.equalsIgnoreCase("B")
|| !userIn.equalsIgnoreCase("C") || !userIn.equalsIgnoreCase("D"));
studentAnswers[i] = userIn.toUpperCase();
}
  
// checking for correct answers
for(int i = 0; i < studentAnswers.length; i++)
{
if(studentAnswers[i].equalsIgnoreCase(correctAnswers[i]))
counterForCorrectAnswers++;
}
  
// display results
System.out.println("\n*** STUDENT REPORT CARD ***\n---------------------------\n"
+ "Number of correct answers = " + counterForCorrectAnswers + "/20" +
"\nNumber of incorrect answers = " + (20 - counterForCorrectAnswers) + "/20" +
"\nPass marks = 15/20 You scored = " + counterForCorrectAnswers + "/20" +
"\nResult: " + ((counterForCorrectAnswers >= 15) ? "Pass" : "Fail"));
}
}

****************************************************************** SCREENSHOT *********************************************************

Add a comment
Know the answer?
Add Answer to:
Java: The local Driver's License Office has asked you to write a program that grades the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT