Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA I have code for my problem , but it doesnt work properly. P.S. i added two classes for this code StdIn and StdOut.: http://introcs.cs.princeton.edu/java/stdlib/StdIn.java.html

JAVA

I have code for my problem , but it doesnt work properly. P.S. i added two classes for this code StdIn and StdOut.:

http://introcs.cs.princeton.edu/java/stdlib/StdIn.java.html

http://introcs.cs.princeton.edu/java/stdlib/StdOut.java.html

Could you fix it and show me output. OUTPUT PLEASE

MY OUTPUT: image text in transcribed

Thank you

Problem: Drivers License Exam The local Drivers License 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 answers: ADBCBABCDACDBDCCADBY our program should store the correct answers shown above in an array. It should ask the user to enter the students answers for each of the 20 questions, and the answers should be stored in another array. After the students answers have been entered, the program should display a message indicating whether the student passed or failed the exam. (A student must correctly answer 15 of the 20 questions to pass the exam.) It should then display the total number of correctly answered questions, the total number of incorrectly answered questions, and a list showing the question numbers of the incorrectly answered questions. Input Validation: Only accept the letters A, B, C, or D as answers.

Code, that i got:

package javaapplication30; import java.util.Scanner;

public class DriversLicense { public static void main (String[] args) { char[] correct = {'B', 'D', 'A', 'A', 'C' , 'A', 'B', 'A', 'C', 'D' , 'B', 'C', 'D', 'A', 'D' , 'C', 'C', 'B', 'D', 'A'};

char[] response = new char [20]; int numCorrect; int numIncorrect; int[] QuestMissed; boolean passed;

for (int a = 0 ; a 'D') { Stdout.println ("Invalid input. Enter answers with A, B, C, or D only!"); response [a] = Stdin.readChar (); } }

Stdout.println ();

passed = examPassed (response, correct); numCorrect = totalCorrect (response, correct); numIncorrect = totalIncorrect (response, numCorrect); QuestMissed = questionsMissed (response, correct);

if (passed) Stdout.print ("You passed!"); else Stdout.print ("You didn't pass!");

Stdout.println (" Below are the details of your marked exam: "); Stdout.println ("#s of correct questions: " + numCorrect); Stdout.println ("#s of incorrect questions: " + numIncorrect);

if (QuestMissed.length > 0) { Stdout.print ("Questions missed: ");

for (int a = 0 ; a

private static int totalCorrect (char[] resp, char[] ans) { int totalCor = 0; for (int a = 0 ; a

private static int totalIncorrect (char[] resp, int right) { return (resp.length - right); }

public static int[] questionsMissed (char[] resp, char[] ans) { int sizeArray = resp.length - totalCorrect (resp, ans); int[] missedQuestions = {};

if (sizeArray

else { missedQuestions = new int [sizeArray]; int position = 0; for (int x = 0 ; x

}

private static boolean examPassed (char[] resp, char[] ans) { int cor; boolean flag = false; cor = totalCorrect (resp, ans); if (cor >= 15) flag = true; return flag; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Expert Oracle9i Database Administration

Authors: Sam R. Alapati

1st Edition

1590590228, 978-1590590225

More Books

Students also viewed these Databases questions

Question

What are Anti-globalists?

Answered: 1 week ago

Question

What did they do? What did they say?

Answered: 1 week ago

Question

What is the basis for Security Concerns in Cloud Computing?

Answered: 1 week ago

Question

Describe the three main Cloud Computing Environments.

Answered: 1 week ago