ITS 3105 SUS Programming ll Questions

Description

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