Hello I need help with this. I am trying to use JOptionpane to ask 5 questions. However I cannot get the program to do anything after an initial selection is made.
Here is the assignment.
Write an application that creates a quiz, which contains at least five questions about a hobby, popular music, astronomy, or any other personal interest. Each question should be a multiple choice question with at least three options. When a user answers a question correctly, display a congratulatory message. If a user responds to a question incorrectly, display an appropriate message as well as a correct answer. At the end of the quiz display the number of correct and incorrect answers and the percentage of correct answers. Save the file as Quiz.java.
1 import javax.swing.*;
2 import javax.swing.JDialog;
3 import javax.swing.JOptionPane;
4
5 public class JOptionPaneTest3
6 {
7 public static void main(String[] args)
8 {
9 String Astronomy = "";
10 String astronomyQuestions;
11
12
JDialog.setDefaultLookAndFeelDecorated(true);
13 Object[] selectionValues = { "Sports",
"Astronomy", "Popular Music" };
14 String initialSelection =
"Sports";
15 Object selection =
JOptionPane.showInputDialog(null, "Which category would you like to
test your knowledge on?",
16 "Knowledge
Quiz", JOptionPane.QUESTION_MESSAGE, null, selectionValues,
initialSelection);
17
18
19
20 while(selection == Astronomy)
21 {
22 JOptionPane.showMessageDialog(null," You
have Selected Astronomy ");
23
24
25 /* Then ask questions here on each topic
using radio buttons*/
26 // for example what is the name of our
galaxy?//
27 /*(a) Milky Way*/
28 /*(b) Galaxy n
Beyond*/
29 /*(c) Galaxy 90210*/
30 /*(d) Galaxy Gemini*/
31
32 /* If correct disply
congratulations*/
33 /* If wrong display correct
answer*/
34
35
36 }
37 }
38 }
Provided Java GUI code as per your requirements.
Screen shot program:

Output:


Code to copy:
//Header file section
import javax.swing.*;
import java.lang.String;
//main class, Quiz.java
public class Quiz
{
//main method
public static void main(String args[])
{
//Declare variables
String question;
int q1 = 0, q2 = 0, q3 = 0, q4 = 0, q5 = 0;
double correct = 0, incorrect = 0;
double percent = 0;
//Quiz contains five questions
/*Each question should be a multiple choice question
with at least three options.
* When a user answers a question correctly, display a
congratulatory message.
* If a user responds to a question incorrectly,
display an appropriate message
* as well as a correct answer.*/
question = JOptionPane.showInputDialog(null,
"Question 1: which of following
is a not hobby:?"
+ "\n1 - Watching movies \n2 -
Killing"
+ "\n3 - Stamp
collection");
q1 = Integer.parseInt(question);
if (q1 == 2)
{
JOptionPane.showMessageDialog(null,
"Congratulations.Correct Answer!");
correct++;
} else
{
JOptionPane.showMessageDialog(null,"Incorrect.
The Correct Answer: 2-Killing.");
incorrect++;
}
question = JOptionPane.showInputDialog(null,
"Question 2. who is not singer "
+ "\n1 - Britney spears \n2 -
Ashok"
+ "\n3 - michael
jacksons");
q2 = Integer.parseInt(question);
if (q2 == 2)
{
JOptionPane.showMessageDialog(null,
"Congratulations.Correct Answer!");
correct++;
} else
{
JOptionPane.showMessageDialog(null,"Incorrect.
The Correct Answer: 2 - Ashok.");
incorrect++;
}
question = JOptionPane.showInputDialog(null,
"Question 3.The largest circular storm in
our solar system is on the surface of"
+ "which of the following planets?"
+ "\n1 - Jupiter \n2 -
Earth"
+ "\n3 - Venus");
q3 = Integer.parseInt(question);
if (q3 == 1) {
JOptionPane.showMessageDialog(null,
"Congratulations.Correct Answer!");
correct++;
} else {
JOptionPane.showMessageDialog(null,"Incorrect.
The Correct Answer: 1 - Jupiter.");
incorrect++;
}
question = JOptionPane.showInputDialog(null,
"Question 4. Who is present president of
america(2015)?"
+ "\n1 - George H. W. Bush \n2
- John Adams"
+ "\n3 - Barack Obama");
q4 = Integer.parseInt(question);
if (q4 == 3) {
JOptionPane.showMessageDialog(null,
"Congratulations.Correct Answer!");
correct++;
} else {
JOptionPane.showMessageDialog(null,"Incorrect.
The Correct Answer: 3 - Barack Obama.");
incorrect++;
}
question = JOptionPane
.showInputDialog(
null,
"Question 5. In 2003, who won
the Award for Best Actress in a Leading Role for her role in The
Hours?"
+ "\n1 - Nicole
Kidman \n2 - Halle Berry"
+ "\n3 -
Cate");
q5 = Integer.parseInt(question);
if (q5 == 1)
{
JOptionPane.showMessageDialog(null,
"Congratulations.Correct Answer!");
correct++;
} else {
JOptionPane.showMessageDialog(null,"Incorrect.
The Correct Answer: 1 - Nicole Kidman.");
incorrect++;
}
//Calculate the percentage of correct answer
percent = (correct * 100) / (correct +
incorrect);
//Display the number of correct and incorrect
answers
//and the percentage of correct answers
System.out.print("Correct Answers: " + correct +
"\n");
System.out.print("Incorrect Answers: " + incorrect +
"\n");
System.out.print("Percentage of correct answers: " +
percent + "%");
}
}
Hello I need help with this. I am trying to use JOptionpane to ask 5 questions....
CS 1102 Unit 5 – Programming Assignment In this assignment, you will again modify your Quiz program from the previous assignment. You will create an abstract class called "Question", modify "MultipleChoiceQuestion" to inherit from it, and add a new subclass of "Question" called "TrueFalseQuestion". This assignment will again involve cutting and pasting from existing classes. Because you are learning new features each week, you are retroactively applying those new features. In a typical programming project, you would start with the...
I need help with this question for programming. The language we use is C++ The program should ask the user if they want to search for a boy or girl name. It should then ask for the name search the appropriate array for the name and display a message saying what ranking that name received, if any. The name files (BoyNames.txt and GirlNames.txt) are in order from most popular to least popular and each file contains two hundred names. The...
CS 1102 Unit 5 – Programming Assignment In this assignment, you will again modify your Quiz program from the previous assignment. You will create an abstract class called "Question", modify "MultipleChoiceQuestion" to inherit from it, and add a new subclass of "Question" called "TrueFalseQuestion". This assignment will again involve cutting and pasting from existing classes. Because you are learning new features each week, you are retroactively applying those new features. In a typical programming project, you would start with the...
Hello can someone help me in my code I left it as comment task #0, task#1, task#2a and task#2b the things that I am missing I'm using java domain class public class Pizza { private String pizzaCustomerName; private int pizzaSize; // 10, 12, 14, or 16 inches in diameter private char handThinDeep; // 'H' or 'T' or 'D' for hand tossed, thin crust, or deep dish, respecitively private boolean cheeseTopping; private boolean pepperoniTopping; private boolean sausageTopping; private boolean onionTopping; private boolean...
I need help with the code below. I am getting an error message I am not sure how to fix import java.util.Scanner; public class DriveTestExams { public static vice main (String[] args);{ Scanner KB = new Scanner (System.in); int IncorrectAns; String[]CA = {"A", "D", "B", "B", "C", "B","A", "B","C", "D","A", "C","D", "B","D", "C","C", "A","D", "A"}; String[]SA = new String [20]; Boolean RightChoice = true; int IncorrectAns = 0; for(int i=o; i <=20; i++){ while (rightchoices); System.out.prinlin ("please enter answer for...
JAVA Hello I am trying to add a menu to my Java code if someone can help me I would really appreacite it thank you. I found a java menu code but I dont know how to incorporate it to my code this is the java menu code that i found. import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.ButtonGroup; import javax.swing.JCheckBoxMenuItem; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JRadioButtonMenuItem; public class MenuExp extends JFrame { public MenuExp() { setTitle("Menu Example");...
Hi I need some help in C programing class and I doing one of the exercise so that I can get better at coding. Suppose you are asked to design a software that helps an elementary school student learn multiplication and division of one-digit integer numbers. The software allows the student to select the arithmetic operation she or he wishes to study. The student chooses from a menu one of two arithmetic operations: 1) Multiplication and 2) Division (quotient). Based...
Describe how you would develop object-oriented features of Java for the Quiz program developed in the Programming Assignments. In particular, describe how the program could use each of the following: class variables, instance variables, inheritance, polymorphism, abstract classes, "this", "super", interfaces, and event listeners. Your Discussion should be at least 250 words in length, but not more than 750 words. QUIZ PROGRAM EXAMPLE: Files "QuestionDialog.java": import java.awt.event.*; import javax.swing.*; public class QuestionDialog extends JDialog implements ActionListener { String answer; public...
please only use import java.util.Scanner
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. A 2. D 3.В 4. B 5, C 6. В 7. A 8.В 9, C 10. D 12. C 13. D 14. B 15. D 16. С 18. A 19. D 20. B Your program should store...
could you please help me with this problem, also I
need a little text so I can understand how you solved the
problem?
import java.io.File; import java.util.Scanner; /** *
This program lists the files in a directory specified by * the
user. The user is asked to type in a directory name. * If the name
entered by the user is not a directory, a * message is printed and
the program ends. */ public class DirectoryList { public static...