Question

In: Computer Science

Driver’s License test. Write a program that grades the written portion of the driver’s license test....

Driver’s License test. Write a program that grades the written portion of the driver’s license test. The test has 20 multiple choice questions. Here are the correct answers: ( use array to store ) 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 A student must correctly answer ( use array to store) 15 of 20 questions to pass test. Write the following methods: Passed : return true if the student passed the test, or false if the student failed boolean Passed( char[ ] solution, char [] answer) totalCorrect: return the total number of correctly answered questions int totalCorrect( char[ ] solution, char [] answer) The main program should ask user to enter a student’s answers and then display the results from calling methods: If the student passed or failed, number of correct answers, number of incorrect answers, Extra credits(10pts) Add another method questionMissed: in integer array containing the question numbers of the question that the student missed Int [] questionMissed(char[] solution, char [] answer) In main method, print out list of question numbers with incorrect answers.

LANGUAGE(JAVA)

Solutions

Expert Solution

Java program that grades the written portion of the driver’s license test :

public class DriverLicense
{
//An array containing a student's answers
private 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's answers
private String[] userAnswers;
int[] missed = new int[correctAnswers.length];

//Process the user's answers
public DriverLicense (String[] Answers)
{
userAnswers = new String[Answers.length];

for (int i = 0; i < Answers.length; i++)
{
userAnswers[i] = Answers[i];
}
}

//Returns a boolean value if correct answers > 15
public boolean passed()
{
if (totalCorrect() >= 15)
return true;
else
return false;
}

//Determines the total correct answers
public int totalCorrect()
{
int correctCount = 0;

for (int i = 0; i < correctAnswers.length; i++)
{
if (userAnswers[i].equalsIgnoreCase(correctAnswers[i]))
{
correctCount++;
}
}
return correctCount;
}

//Determines the total incorrect 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[] questionsMissed()
{
return missed;
}

}
//end of DriverLicense class

/* The DriverLicenseApplication class demonstrates the methods of DriverExam class. */


import java.util.Scanner;

public class DriverLicenseApplication
{
public static void main(String[] args)
{
System.out.println(" Driver's License Test ");
Scanner input = new Scanner(System.in);

System.out.println(" 20 Multiple-Choice Questions ");
System.out.println(" Mark A, B, C, D ");

//Inputting string
String[] answers = new String[20];
String answer;

for (int i = 0; i < 20; i++)
{
do
{
System.out.println((i+1) + ": ");
answer = input.nextLine();
} while (!isValidAnswer(answer));

answers[i] = answer;
}

//Process
DriverLicense license = new DriverExam(answers);

//Results
System.out.println(" RESULTS ");

//Outputting total correct
System.out.println("Total Correct: " + license.totalCorrect());

//Outputting total incorrect
System.out.println("Total Incorrect: " + license.totalIncorrect());

String passed = license.passed() ? "YES" : "NO";

//Result pass or fail
System.out.println("Passed: " + passed);

if (license.totalIncorrect() > 0)
{
System.out.println("The incorrect answers are: ");

int missedIndex;

for (int i = 0; i < license.totalIncorrect(); i++)
{
missedIndex = exam.questionsMissed()[i]+1;
System.out.println(" " + missedIndex);
}
}
} //end of main function

//Returns true when answer is valid
public static boolean isValidAnswer (String answer)
{
return "A".equalsIgnoreCase(answer) ||
"B".equalsIgnoreCase(answer)
|| "C".equalsIgnoreCase(answer) ||
"D".equalsIgnoreCase(answer);
}
} //end of Test class


Related Solutions

The driver’s license office DMV has asked you to write a program that grades the written...
The driver’s license office DMV has asked you to write a program that grades the written portion of the driver’s license questions. The questions has 20 multiple-choice questions. Here are the correct answers: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 B D A A A C B C D A D C C D D B A B C D Your program should store these correct answers...
The local driver's license office has asked you to design a program that grades the written...
The local driver's license office has asked you to design 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: B D A A C A B A C D B C D A D C C B D A Your program should store these correct answers in an list. (Store each question's correct answer in an element of a String list). The program should ask...
The local driver's license office has asked you to design a program that grades the written...
The local driver's license office has asked you to design a program that grades the written portion of the driver's license test. The test has 20 multiple choice questions. Here are the correct answers: B D A A C A B A C D B C D A D C C B D A Your program should store these correct answers in an list. (Store each question's correct answer in an element of a String list). The program should ask...
The local driver’s license center processes applications for driver’s license renewals through the following three steps....
The local driver’s license center processes applications for driver’s license renewals through the following three steps. First, the customer registers with the receptionist, who updates the customer’s information in the database. This first step takes 2 minutes per customer. Then the customer visits one of two cashiers to pay the associated fees for the license renewal. This takes 8 minutes per customer because several forms must be printed from the computer and signed by the customer. Finally, the customer visits...
A sample of 31 people took a written driver’s license exam. Two variables were measured on...
A sample of 31 people took a written driver’s license exam. Two variables were measured on them: The result of the exam (0 = fail, 1 = pass), and how much time (in hours) the person studied for the exam. Using the data, fit an appropriate regression model to determine whether time spent studying is a useful predictor of the chance of passing the exam. Formally assess the overall fit of the model. Formally assess whether time spent studying is...
You need to get a driver’s license. There is a clerk A, a clerk B, a...
You need to get a driver’s license. There is a clerk A, a clerk B, a clerk C, a clerk D, and a clerk E. Assuming that the work each clerk does is value adding, answer these two questions. Calculate the amount of time in the process that is value adding and the amount that is wait time. What is the bottleneck? Department of Motor Vehicle process: A. Check in, clerk A puts your name into the computer. Clerk A...
Instructions: Write a program to calculate students’ average test scores and their grades. You may assume...
Instructions: Write a program to calculate students’ average test scores and their grades. You may assume the following input data: Johnson 85 83 77 91 76 Aniston 80 90 95 93 48 Cooper 78 81 11 90 73 Gupta 92 83 30 69 87 Blair 23 45 96 38 59 Clark 60 85 45 39 67 Kennedy 77 31 52 74 83 Bronson 93 94 89 77 97 Sunny 79 85 28 93 82 Smith 85 72 49 75 63...
Directions: Write a program to calculate students’ average test scores and their grades. You may assume...
Directions: Write a program to calculate students’ average test scores and their grades. You may assume the following input data: Johnson 85 83 77 91 76 Aniston 80 90 95 93 48 Cooper 78 81 11 90 73 Gupta 92 83 30 69 87 Blair 23 45 96 38 59 Clark 60 85 45 39 67 Kennedy 77 31 52 74 83 Bronson 93 94 89 77 97 Sunny 79 85 28 93 82 Smith 85 72 49 75 63...
Program should be written in Java a) Write a program that asks the user to enter...
Program should be written in Java a) Write a program that asks the user to enter the approximate current population of India. You should have the computer output a prompt and then YOU (as the user should enter the population.)  For testing purposes you may use the value of 1,382,000,000 from August 2020. Assume that the growth rate is 1.1% per year. Predict and print the predicted population for 2021 and 2022. The printout should include the year and the estimated...
Write a program in python to read from a file the names and grades of a...
Write a program in python to read from a file the names and grades of a class of students to calculate the class average, the maximum, and the minimum grades. The program should then write the names and grades on a new file identifying the students who passed and the students who failed. The program should consist of the following functions: a) Develop a getGrades() function that reads data from a file and stores it and returns it as a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT