Question: [Write an application that contains an array of 10 multiple-choice quiz questions related to your favorite hobby. Each question contains three answer choices. Also create

[Write an application that contains an array of 10 multiple-choice quiz questions related to your favorite hobby. Each question contains three answer choices. Also create an array that holds the correct answer to each questionA, B, or C. Display each question and verify that the user enters only A, B, or C as the answerif not, keep prompting the user until a valid response is entered. If the user responds to a question correctly, display Correct!; otherwise, display The correct answer is and the letter of the correct answer. After the user answers all the questions, display the number of correct and incorrect answers. Save the file as Quiz.java.] This is the prompt for the assignment, but I need help editing my code. I can't get my code to display the number of correct and incorrect answers. Here is what I have so far:

import java.util.*; import java.io.*; public class Quiz1 { public static void main(String[] args) { Questions(); } public static void Questions() { Scanner console = new Scanner(System.in); String[][] Q = new String[20][]; //This loop constructs a jagged array for (int i = 0; i < 20; i++) { if (i == 0 || i % 2 == 0) { Q[i] = new String[1]; } else { Q[i] = new String[3]; } } String[] A = new String[10]; //Array for answers Q[0][0] = "John F. Kennedy was assasinated in which state?"; Q[1][0] = "A) New York"; Q[1][1] = "B) Austin"; Q[1][2] = "C) Miami"; A[0] = "B"; Q[2][0] = "Who fought in the war of 1812?"; Q[3][0] = "A) Andrew Jackson"; Q[3][1] = "B) Napolean"; Q[3][2] = "C) King Arthur"; A[1] = "A"; Q[4][0] = "WWI began in..."; Q[5][0] = "A) 1910"; Q[5][1] = "B) 1914"; Q[5][2] = "C) 1920"; A[2] = "B"; Q[6][0] = "Which country did Japan ally themselves with during WWI?"; Q[7][0] = "A) China"; Q[7][1] = "B) France"; Q[7][2] = "C) Germany"; A[3] = "C"; Q[8][0] = "Adolf Hitler was also known as..."; Q[9][0] = "A) Fuhrer"; Q[9][1] = "B) Man of Steel"; Q[9][2] = "C) Dino"; A[4] = "A"; Q[10][0] = "Who was the first Western explorer to reach China?"; Q[11][0] = "A) John Smith"; Q[11][1] = "B) Marco Polo"; Q[11][2] = "C) Hernan Cortes"; A[5] = "B"; Q[12][0] = "The Magna Carta corresponds to which country?"; Q[13][0] = "A) England"; Q[13][1] = "B) Thailand"; Q[13][2] = "C) Korea"; A[6] = "A"; Q[14][0] = "WWII ended in which year?"; Q[15][0] = "A) 1945"; Q[15][1] = "B) 1944"; Q[15][2] = "C) 1941"; A[7] = "A"; Q[16][0] = "The Industrial Revolution first took place in..."; Q[17][0] = "A) France"; Q[17][1] = "B) America"; Q[17][2] = "C) England"; A[8] = "C"; Q[18][0] = "What does the \"D\" in D-Day stand for?"; Q[19][0] = "A) Death"; Q[19][1] = "B) Day"; Q[19][2] = "C) Dooms"; A[9] = "B"; int a = 0; int correctCount = 0; int counter = 0; for (int i = 0; i < Q.length; i++) { for (int j = 0; j < Q[i].length; j++) { System.out.print(Q[i][j] + " "); if (j >= 2) { counter = TakeQuiz(A, a, correctCount); a++; } } } System.out.print("Total: " + counter); } public static int TakeQuiz(String[] A, int a, int correctCount) { Scanner console = new Scanner(System.in); String response = console.nextLine(); response = response.toUpperCase(); while (!response.equals("A") && !response.equals("B") && !response.equals("C")) { System.out.println("Input not appropriate. Enter a valid response: "); response = console.nextLine(); } if (response.equals(A[a])) { correctCount++; System.out.println("Correct!!"); System.out.println(); } else { System.out.println("Incorrect, the correct answer is: " + A[a]); System.out.println(); } return correctCount; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!