Question

License test The Los Angeles driver's license office has asked you to create an application that...

License test

The Los Angeles driver's license office has asked you to create an application that grades the written portion of the drivers license test. The test has 15 multiple-choice questions. Here are the correct answers

(You may create your own correct answers if you like)

1. C 2. D     3. B 4. A      5. C

6. D 7. B     8. A     9. C     10. D

11. A 12. C   13. D    14. A     15. B

A student must answer 10 of the 15 questions to pass the test.

Write a class named DriverTest that holds the correct answers to the test in an array. The class should also have an array that holds the student's answers. The following methods should be provided.

- Passed. Returns true of the student passes or false if the student fails

- totalCorrect          Returns the total correctly answered.

- totalIncorrect       Returns the total incorrectly answered.

- questionsMissed Returns an array containing the missed questions.

- YourScore           Returns the percentage correct.

Include a separate demo program file that calls the methods from DriverTest.

Valid input: Only the letters A, B, C, or D are acceptable answers to questions.

Program must be in Java

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

Program Screenshot:

Definition of DriverExan cla33 class DriverExan an array of students answers private String[] correct Answers- { A, В,

/ Display the number of incorrect answers System.out.println (Number of Incorrect answers: + e.totalIncorrect ()) String pa

Sample Output:

Drivers License Exam 15 Multiple choice questions Mark A,B,C,D . 3: b 5: d 6: C 7: b 8: a 9: C 10: d 11: C 12: b 13: a 14: d

Code to copy:

// Definition of DriverExam class
class DriverExam
{
   // an array of student's answers.
   private String[] correctAnswers = { "A", "B", "C", "B",
           "D", "A", "B", "D", "C", "D", "C",
           "C", "A", "A", "B" };
   private String[] userAnswers;
   int[] missed = new int[correctAnswers.length];
   // Constructor
   public DriverExam(String[] Answers)
   {
       userAnswers = new String[Answers.length];
       for (int i = 0; i < Answers.length; i++)
       {
           userAnswers[i] = Answers[i];
       }
   }

   //Implementation of passed method
   public boolean passed()
   {
       if (totalCorrect() >= 10)
           return true;
       else
           return false;
   }

   //Implementation of totalCorrect
   public int totalCorrect()
   {
       int correctCount = 0;
       for (int i = 0; i < correctAnswers.length; i++)
       {
           if (userAnswers[i].equalsIgnoreCase(correctAnswers[i]))
           {
               correctCount++;
           }
       }
       return correctCount;
   }
  
   //Implementation of totalIncorrect
   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;
   }

   //Implementation of Missed questions.
   public int[] questionsMissed()
   {
       return missed;
   }
}


-------------------------------------------------------------------

// import packages
import java.util.Scanner;


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

       System.out.println(" 15 Multiple choice questions Mark A,B,C,D .");
       // Inputting string
       String[] answers = new String[15];
       String answer;
       for (int i = 0; i < 15; i++)
       {
           do
           {
               System.out.print((i + 1) + ": ");
               answer = kb.nextLine();
           } while (!isValidAnswer(answer));
           answers[i] = answer;

       }
       // Create an object for DriverExam class
       DriverExam e = new DriverExam(answers);
       System.out.println("       RESULTS        ");
       // Display the number of correct answers
       System.out.println("Number of correct answers: " + e.totalCorrect());
       // Display the number of incorrect answers
       System.out.println("Number of Incorrect answers: " + e.totalIncorrect());
       String passed = e.passed() ? "YES" : "NO";
       // Display the pass or fail
       System.out.println("Passed: " + passed);
       if (e.totalIncorrect() > 0)
       {
           System.out.println("Missed Questions are:");
           int missedIndex;
           for (int i = 0; i < e.totalIncorrect(); i++)
           {
               missedIndex = e.questionsMissed()[i] + 1;
               System.out.print(" " + missedIndex);
           }
       }
   }

   public static boolean isValidAnswer(String answer)
   {
       return "A".equalsIgnoreCase(answer) || "B".equalsIgnoreCase(answer) || "C".equalsIgnoreCase(answer)
               || "D".equalsIgnoreCase(answer);
   }
}

Add a comment
Know the answer?
Add Answer to:
License test The Los Angeles driver's license office has asked you to create an application that...
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
  • Using C++ 1. Driver's The local driver's license office has asked you to create an application...

    Using C++ 1. Driver's The local driver's license office has asked you to create an application that grades the written portion of the driver's license exam. The exam has 20 multiple-choice questions. Here are the correct answers 16. C 17.С 18. B 19. D 20. A 1. B 2. D 3. A 12. C 13. D 14. A 15. D 7.В 9.С 10. D 5. С Your program should store these correct answers in an array. It should ask the...

  • C# Visual Studio -The local driver's license office has asked you to create an application that...

    C# Visual Studio -The local driver's license office has asked you to create an application 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 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 Your program should...

  • please only use import java.util.Scanner Driver's License Exam The local Driver's License Office has asked you...

    please only use import java.util.Scanner Driver's License Exam 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. A 2. D 3.В 4. B 5, C 6. В 7. A 8.В 9, C 10. D 12. C 13. D 14. B 15. D 16. С 18. A 19. D 20. B Your program should store...

  • 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...

  • Visual Basic zoow Driver's License Exam The local Registry of Motor Vehicles oflice has asked you to create an application that grades the written portion of the driver's license exam. The ex...

    Visual Basic zoow Driver's License Exam The local Registry of Motor Vehicles oflice has asked you to create an application that grades the written portion of the driver's license exam. The exam has 20 multiplc choice questions. Her ar the orrect answers to the questions: 6. A 7.13 8. A 9. C 10. D 16. С 12. C 13. D 14. A 15. D 2. D 3. A 5, C Your application should slore the correcl answers in an array....

  • PYTHON CODE PLEASEEEEE. Driver’s License Exam 20PTS PYTHON AND FLOWCHART The local driver’s license office has...

    PYTHON CODE PLEASEEEEE. Driver’s License Exam 20PTS PYTHON AND FLOWCHART 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: 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 these correct answers in an array. (Store each question’s correct answer in...

  • The local driver’s license office has asked you to write a program that grades the written...

    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: 1.A 6.B 11.C 16.B 2 21.B 2.C 7.C 12.A 17.A 22.C 3.B 8.D 13.B 18.C 23.A 4.B 9.A 14.C 19.A 24.D 5.D 10.B 15.A 20.D 25.B First, the application displays messages to ask for the information of current candidate about...

  • Please answer Question 4 WITH A C# PROGRAM!!!!!! THANK YOU! File Edit View History Bookmarks Tools...

    Please answer Question 4 WITH A C# PROGRAM!!!!!! THANK YOU! File Edit View History Bookmarks Tools Help Share GEP IIIA Moorhead, MN 10-Day Weathe X N NDSU Faculty and Staff | North x D C#.NET - CSCI 213: Modern Sol X VitalSource Bookshelf: Starting x + + → OO - https://bookshelf.vitalsource.com/#/books/9780134400433/cf1/6 90% *** * Cambie Meble alle... S N 10 Crosby Derek Lam ... Alterna Caviar Anti-Ag... U C# Tutorial For Beginn... BE Celsius Fahrenheit con... Charter Club Sweater. Folklorama...

  • 3. Define a class License. A License has a license number and an suggest using java.time.LocalDate, but there are o...

    3. Define a class License. A License has a license number and an suggest using java.time.LocalDate, but there are other possibilities). Then do the following: expiration date ( (a) Think what it might mean for two License instances to represent the same real- world license. Write the Boolean equals method that takes another License as argument and returns true if the two Licenses are "equal" in this sense. The block comment for your method should explain how you are doing...

  • In this assignment you will create two Java programs: The first program will be a class...

    In this assignment you will create two Java programs: The first program will be a class that holds information (variables) about an object of your choice and provides the relevant behavior (methods) The second program will be the main program which will instantiate several objects using the class above, and will test all the functions (methods) of the class above. You cannot use any of the home assignments as your submitted assignment. Your programs must meet the following qualitative and...

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