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....
Please help, Array does not print properly. I need to print out the 8 class numbers entered by the user ! Java only using J option pane, you cannot use ulti or anything else only J option pane Program compiles but does not print the array correctly! import javax.swing.JOptionPane; public class programtrial { public static void main(String[] args) { int newclass = 0; int countclass = 0; final int class_Max = 8; int[] classarray =...
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 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...
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");...
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...
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...
Input hello, I need help completing my assignment for java,Use the following test data for input and fill in missing code, and please screenshot output. 1, John Adam, 3, 93, 91, 100, Letter 2, Raymond Woo, 3, 65, 68, 63, Letter 3, Rick Smith, 3, 50, 58, 53, Letter 4, Ray Bartlett, 3, 62, 64, 69, Letter 5, Mary Russell, 3, 93, 90, 98, Letter 6, Andy Wong, 3, 89,88,84, Letter 7, Jay Russell, 3, 71,73,78, Letter 8, Jimmie Wong,...
12p I need help this is Python EXCEPTIONS: It's easier to ask forgiveness than permission. Try the code and catch the errors. The other paradigm is 'Look before you leap' which means test conditions to avoid errors. This can cause race conditions. 1.Write the output of the code here: class MyError(Exception): pass def notZero(num): if num == 0: raise MyError def run(f): try: exec(f) except TypeError: print("Wrong type, Programmer error") except ValueError: print("We value only integers.") except Zero Division Error:...
I have a java project that I need help trying to finish. I have most of it completed but the issue I am running into is adding numbers with different lengths. Project requirements: . Use a Stack ADT with the implementation of your choice (Array or Link), it should not make a difference 2.Read two “integer” numbers from the user. Hint: You don’t need to use an int type when you read, it may be easier to parse the input...
In java language here is my code so far! i only need help with the extra credit part For this project, you will create a Rock, Paper, Scissors game. Write a GUI program that allows a user to play Rock, Paper, Scissors against the computer. If you’re not familiar with Rock, Paper, Scissors, check out the Wikipedia page: http://en.wikipedia.org/wiki/Rock-paper-scissors This is how the program works: The user clicks a button to make their move (rock, paper, or scissors). The program...