(Homework Solution): Need Java Code for this assignment I am using Eclipse IDE

Need Java Code for this assignment

I am using Eclipse IDE

6. 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: 2. D 618 3. A 6. A 7.В 8. A 9. C 10. D 12. C 13. D 14. A 15. D 16. С 17.С 18. В 19. D 20. A A student must correctly answer 15 of the 20 questions to pass the exam. Write a class named DriverExam that holds the correct answers to the exam in an array field. The class should also have an array field that holds the students answers. The class should have the following methods . passed. Returns true if the student passed the exam, or false if the student failed . totalCorrect. Returns the total number of correctly answered questions totalincorrect. Returns the total number of incorrectly answered questions . questionsMissed. An int array containing the question numbers of the questions that the student missed Demonstrate the class in a complete program that ask displays the results returned from the DriverExam classs methods. s the user to enter a students answers, and then Input Validation: Only accept the letters A, B, C, or D as answers.

6. 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. 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 15 of the 20 questions to pass the exam. Write a class named DriverExam that holds the correct answers to the exam in an array field. The class should also have an array field that holds the student’s answers. The class should have the following methods: passed. Returns true if the student passed the exam, or false if the student failed totalCorrect. Returns the total number of correctly answered questions totalIncorrect. Returns the total number of incorrectly answered questions questionsMissed. An int array containing the question numbers of the questions that the student missed Demonstrate the class in a complete program that asks the user to enter a student’s answers, and then displays the resuts returned from the DriverExam class’s methods. Input Validation: Only accept the letters A, B, C, or D as answers.

Ratings will be given to correct answer,

Thank you!

6. 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: 2. D 618 3. A 6. A 7.В 8. A 9. C 10. D 12. C 13. D 14. A 15. D 16. С 17.С 18. В 19. D 20. A A student must correctly answer 15 of the 20 questions to pass the exam. Write a class named DriverExam that holds the correct answers to the exam in an array field. The class should also have an array field that holds the student’s answers. The class should have the following methods . passed. Returns true if the student passed the exam, or false if the student failed . totalCorrect. Returns the total number of correctly answered questions totalincorrect. Returns the total number of incorrectly answered questions . questionsMissed. An int array containing the question numbers of the questions that the student missed Demonstrate the class in a complete program that ask displays the results returned from the DriverExam class’s methods. s the user to enter a student’s answers, and then Input Validation: Only accept the letters A, B, C, or D as answers.

Expert Answer

Solution:

package com.student;

import java.util.Scanner;

public class DriverExam {
String correctAnswer[] = { “B”, “D”, “A”, “A”, “C”, “A”, “B”, “A”, “C”, “D”, “B”, “C”, “D”, “A”, “D”, “C”, “C”, “B”,
“D”, “A” };

String studentCorrectAnswer[] = new String[20];

public boolean passed() {
return totalCorrect() >= 15 ? true : false;
}

public int totalCorrect() {
int totalCorrectAnswer = 0;
for (int i = 0; i < correctAnswer.length; i++) {
if (correctAnswer[i].equals(studentCorrectAnswer[i])) {
totalCorrectAnswer++;
}
}
return totalCorrectAnswer;
}

public int totalIncorrect() {
int totalIncorrectCorrectAnswer = 0;
for (int i = 0; i < correctAnswer.length; i++) {
// check if answered not matched
if (!(correctAnswer[i].equals(studentCorrectAnswer[i]))) {
if (studentCorrectAnswer[i] != null) {
totalIncorrectCorrectAnswer++;
}
}
}
return totalIncorrectCorrectAnswer;
}

public int totalQuestionMissed() {
int totalQuestionMissed = 0;
for (int i = 0; i < correctAnswer.length; i++) {
// check if answered not matched, if not matched then might be the
// index value is null if null then its not attempted by student
if (!(correctAnswer[i].equals(studentCorrectAnswer[i]))) {
if (studentCorrectAnswer[i] == null) {
totalQuestionMissed++;
}
}
}
return totalQuestionMissed;
}

public static void main(String[] args) {
DriverExam driverExam = new DriverExam();
Scanner in = new Scanner(System.in);
while (true) {
System.out.println(“Do you want to continue answer Y or N”);
String iscontinue = in.nextLine();
if (“Y”.equalsIgnoreCase(iscontinue)) {

} else if (“N”.equalsIgnoreCase(iscontinue)) {
break;
} else {
System.out.println(“please provide input in Y or N in order to continue or pause your answering”);
continue;
}
System.out.println(“Please Enter your Question Number”);
String s1 = in.nextLine();
int index = 0;
try {
index = Integer.parseInt(s1);
index = index – 1;
if (index > driverExam.studentCorrectAnswer.length – 1) {
System.out.println(“please enter value less than 21”);
continue;
}
} catch (Exception e) {
System.out.println(“please provide question number in integer value”);
continue;
}
System.out.println(“Please Enter Your Answer Now”);
String answer = in.nextLine();
if (“A”.equals(answer) || “B”.equals(answer) || “C”.equals(answer) || “D”.equals(answer)) {
driverExam.studentCorrectAnswer[index] = answer;
} else {
System.out.println(“Please enter option in A B C D only”);
}

}
System.out.println(“is passed=”+driverExam.passed());
System.out.println(“total correct answer=” + driverExam.totalCorrect());
System.out.println(“total incorrect answer=” + driverExam.totalIncorrect());
System.out.println(“total missed question=” + driverExam.totalQuestionMissed());
}

}

OUTPUT

Do you want to continue answer Y or N
y
Please Enter your Question Number
1
Please Enter Your Answer Now
B
Do you want to continue answer Y or N
T
please provide input in Y or N in order to continue or pause your answering
Do you want to continue answer Y or N
Y
Please Enter your Question Number
2
Please Enter Your Answer Now
D
Do you want to continue answer Y or N
Y
Please Enter your Question Number
3
Please Enter Your Answer Now
A
Do you want to continue answer Y or N
Y
Please Enter your Question Number
4
Please Enter Your Answer Now
A
Do you want to continue answer Y or N
9
please provide input in Y or N in order to continue or pause your answering
Do you want to continue answer Y or N
Y
Please Enter your Question Number
9
Please Enter Your Answer Now
N
Please enter option in A B C D only
Do you want to continue answer Y or N
Y
Please Enter your Question Number
9
Please Enter Your Answer Now
C
Do you want to continue answer Y or N

please provide input in Y or N in order to continue or pause your answering
Do you want to continue answer Y or N
Y
Please Enter your Question Number
7
Please Enter Your Answer Now
A
Do you want to continue answer Y or N
N
is passed=false
total correct answer=5
total incorrect answer=1
total missed question=14

#If you have any question please feel free to ask and if you like give thumbs up thx

iWriteHomework
Order NOW for a 10% Discount
Pages (550 words)
Approximate price: -

Why Us?

Top Quality and Well-Researched Papers

All ourbpapers are written from scratch. In fact, Clients who ask for paraphrasing services are highly discouraged. We have writers ready to craft any paper from scratch and deliver quality ahead of time.

Professional and Experienced Academic Writers

Our writers keeps you posted on your papers progress - providing you with paper outline/draft. You are also at liberty to communicate directly with your writer.

Free Unlimited Revisions

If you think we missed something, send your order for a free revision. You have 10 days to submit the order for review after you have received the final document. You can do this yourself after logging into your personal account or by contacting our support.

Prompt Delivery and 100% Money-Back-Guarantee

All papers are always delivered on time, in many cases quite ahead of time. In case we need more time to master your paper, we may contact you regarding the deadline extension. In case you cannot provide us with more time, a 100% refund is guaranteed.

Original & Confidential

We use several writing tools checks to ensure that all documents you receive are free from plagiarism. Our editors carefully review all quotations in the text. We also promise maximum confidentiality in all of our services.

24/7 Customer Support

Our support agents are available 24 hours a day 7 days a week and committed to providing you with the best customer experience. Get in touch whenever you need any assistance.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Services

No need to work on your paper at night. Sleep tight, we will cover your back. We offer all kinds of writing services.

Essays

Essay Writing Service

No matter what kind of academic paper you need and how urgent you need it, you are welcome to choose your academic level and the type of your paper at an affordable price. We take care of all your paper needs and give a 24/7 customer care support system.

Admissions

Admission Essays & Business Writing Help

An admission essay is an essay or other written statement by a candidate, often a potential student enrolling in a college, university, or graduate school. You can be rest assurred that through our service we will write the best admission essay for you.

Reviews

Editing Support

Our academic writers and editors make the necessary changes to your paper so that it is polished. We also format your document by correctly quoting the sources and creating reference lists in the formats APA, Harvard, MLA, Chicago / Turabian.

Reviews

Revision Support

If you think your paper could be improved, you can request a review. In this case, your paper will be checked by the writer or assigned to an editor. You can use this option as many times as you see fit. This is free because we want you to be completely satisfied with the service offered.

× Contact Live Agents