Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Follow the comments in the code below: add 8 more questions and answers and at the end tell the user how many right and wrong

Follow the comments in the code below: add 8 more questions and answers and at the end tell the user how many right and wrong they got for a score.

import javax.swing.*; public class Quiz { public static void main(String[] args) { String[] questions = {"How many players on a basketball team? A. 5 B. 6 C. 7", "How many points for a basket? A. 1 B. 2 C. 3", "How many points for a free throw? A. 1 B. 2 C. 3"}; //Add 8 more questions and answers char[] answers = {'A', 'B','A' }; char ans = ' '; int x, correct = 0; String entry; boolean isGood; for(x = 0; x < questions.length; ++x) { isGood = false; int firstError = 0; while(!isGood) { isGood = true; entry = JOptionPane.showInputDialog (null,questions[x]); ans = entry.charAt(0); if(ans != 'A' && ans != 'B' && ans != 'C') { isGood = false; if(firstError == 0) { questions[x] = questions[x] + " Your answer must be A, B or C."; firstError = 1; } } } if(ans == answers[x]) { ++correct; JOptionPane.showMessageDialog(null, "Correct!"); } else JOptionPane.showMessageDialog(null, "The correct answer is " + answers[x]); } // Using JOptionPane.showMessageDialog tell the user how many they got right and wrong } }

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

Relational Database And Transact SQL

Authors: Lucy Scott

1st Edition

1974679985, 978-1974679980

Students also viewed these Databases questions