Create a java applicaiton that creates a quiz application that asks the user 5 m
ID: 3840294 • Letter: C
Question
Create a java applicaiton that creates a quiz application that asks the user 5 multiple choice questions, prompts for an answer, then advises the user if their answer is correct or incorrect. If the user provides the wrong answer the application should provide the user with the correct answer. After the user completes the 5 questions the application should provide the user with a summary of their results including the number of correct and incorrect answers as well as their score (percent).
Here is a sample question:
What is the state capital of Connecticut:
A. Bridgeport
B. Bristol
C. Hartford
D. Norwalk
Explanation / Answer
public static void main(String[] args) { String[] multiChoice1; Scanner input = new Scanner(System.in); multiChoice1 = new String[5]; multiChoice1[0] = "1. Which country currently emits the most greenhouse gases? "; multiChoice1[1] = "blah blah"; multiChoice1[2] = "blah blah"; multiChoice1[3] = "blah blah"; multiChoice1[4] = "blah blah"; String userSelect1 = multiChoice1[0]; if(userSelect1==multiChoice1[0]){ System.out.println(multiChoice1[0]); System.out.println("A. United States"); System.out.println("B. China"); System.out.println("C. India"); System.out.println("D. England"); System.out.println(); System.out.print("Your answer: "); String uSelect1 = input.next(); switch (uSelect1.toUpperCase()){ case "A": uSelect1 = "United States"; System.out.println("Incorrect! "); break; case "B": uSelect1 = "China"; System.out.println("Correct! "); scorePro++; score++; break; case "C": uSelect1 = "India"; System.out.println("Incorrect! "); break; case "D": uSelect1 = "England"; System.out.println("Incorrect! "); break; default: uSelect1 = "Incorrect, choice. "; break; } } // more multiple choice questions with similar structure }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.