Java Driver License Online Test The local driver\'s license office has asked you
ID: 3718996 • Letter: J
Question
Java
Driver License Online Test The local driver's license office has asked you to write a program that grades the written portion of the driver's license Rules and Signals Test. The driver license test has 25 multiple choice questions. The set of answer keys is: 11.C 12.A 13.B 14.? 15.A 1.A 2.? 6.B 7,? 8.D 9.A 10.B 16.B 17.A 18.C 19.A 20.D 21.B 22.C 23.A 24.D 25.B 4.B 5.D First, the application displays messages to ask for the information of current candidate about last name, first name, SS number to create a Test account When the canidate is ready, display the test instruction, questions and read answers LICENSE THERE ARE 25 MULTIPLE CHOICE QESTI ONS Question 1: The users answer the question by typing a letter A, B, C or D for each question If users type other keys than A, B, C or D; display message "Invalid key - Retype answer of current question before moving on and allow users to retype the All the answers and the key set should be sent to the Test account in array type to evaluate the result. The result will be displayed on the screen in the following format, where the date is current date and Driver's license number is a combination of two random 4-digit numbers DRIVER LICENSE TEST RESULT Driver's name: SS Number Phone Number Address Driver's License Test date Result: Missed Questions: Smith, James 2141234567 123 Plano Rd Dallas TX 75243 12345678 03/15/2018 PASSED 5, 12, 15 The program will be available for other candidates to test until users choose to exitExplanation / Answer
Answer :
public class DriveExam
{
// an array of student's answers.
private final String[] correctAnswers = {"B","D","A","A","C","A","B","A","C","D","B","C","D","A","D","C","C","B","D","A"};
//Store the User answers
private final String[] userAnswers;
int[] missed = new int [correctAnswers. length];
// Process the user answers
public DriveExam(String[] Answers)
{
userAnswers = new String[Answers.length];
for (int i= 0; i< Answers.length; i++)
{
userAnswers[i] = Answers[i];
}
}
//return boolean value if correct answers > 15
public boolean passed()
{
if(totalCorrect()>= 15)
return true;
else
return false;
}
// total Correct answers
public int totalCorrect()
{
int correctCount=0;
for (int i =0; i < correctAnswers.length;i++)
{
if (userAnswers[i].equalsIgnoreCase(correctAnswers[i]))
{
// missed [correctCount]= i;
correctCount++;
}
}
return correctCount;
}
// total Correct answers
public int totalInCorrect()
{
int incorrectCount=0;
for (int i =0; i < correctAnswers.length;i++)
{
if (!userAnswers[i].equalsIgnoreCase(correctAnswers[i]))
{
missed [incorrectCount]= i;
incorrectCount++;
}
}
return incorrectCount;
}
// Missed questions.
public int[] questionMissed()
{
return missed;
}
}
___________________
ExamApplication.java
import java.util.Scanner;
public class ExamApplication {
public static void main(String[] args) {
System.out.println("Driver's Lincense Exam");
//scanner class object is used to read the inputs entered by the user
Scanner kb=new Scanner(System.in);
System.out.println("20 Multiple choice questions ");
// Creating the array of type String
String [] answers = new String [20];
String answer;
System.out.print("Enter Driver’s name:");
String name=kb.nextLine();
System.out.print("Enter SS Number:");
int ssNum=kb.nextInt();
System.out.print("Enter Phone Number:");
int phoneNum=kb.nextInt();
kb.nextLine();
System.out.print("Enter Address: ");
String address=kb.nextLine();
System.out.print("Enter Driver’s Licence:");
int licence=kb.nextInt();
System.out.print("Enter Test date:");
String testDate=kb.next();
for (int i =0; i <20;i++)
{
do
{
System.out.print((i+1)+":");
answer = kb.nextLine();
}
while (!isValidAnswer(answer));
answers[i]=answer;
}
//Process
DriveExam exam= new DriveExam(answers);
System.out.println(" DRIVER LICENSE TEST RESULT");
System.out.println("Driver’s name:"+name);
System.out.println("SS Number:"+ssNum);
System.out.println("Phone Number:"+phoneNum);
System.out.println("Enter Address: "+address);
System.out.println("Driver’s Licence:"+licence);
System.out.println("Test date:"+testDate);
displayResult(exam);
}
private static void displayResult(DriveExam exam) {
String passed = exam.passed()? "Yes ":" No";
// result pass or fail
System.out.println ("Passed :" +passed);
if (exam.totalInCorrect()>0)
{
System.out.println("The incorrect answers are");
int missedIndex;
for (int i = 0; i < exam.totalInCorrect();i++)
{
missedIndex = exam.questionMissed()[i]+1;
System.out.print(" "+missedIndex);
}
}
}
// return true when the answer is valid
public static boolean isValidAnswer(String answer)
{
return "A".equalsIgnoreCase(answer)|| "B".equalsIgnoreCase(answer)|| "C".equalsIgnoreCase(answer)||"D".equalsIgnoreCase(answer);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.