dimanche 28 février 2016

How will the condition work in JOptionPane?

I'm trying to make quiz program with two category: Java or C++ using JOptionPane and I'm trying to make a question with 4 options but I don't know how the condition will work and how will the score will be store.

import javax.swing.JOptionPane;

public class Quiz1
 {
  public static void main(String[] args) 
  {

    int score = 0;
    JOptionPane.showMessageDialog(null,"WELCOME");
    String name = JOptionPane.showInputDialog(null,"Enter Your Name: ");

    String [] Intro = new String [] {"JAVA","C++"};
    int option = JOptionPane.showOptionDialog(null, "Choose a Category","Menu",JOptionPane.YES_NO_OPTION,
    JOptionPane.PLAIN_MESSAGE, null, Intro, Intro[0]);


    if (option == JOptionPane.YES_OPTION) // I just make YES or NO option since there are 2 choices
    {
        JOptionPane.showMessageDialog(null, "Hello "+ name + "\n Welcome to Java Quiz!");
        JOptionPane.showMessageDialog(null, "1. Please read the questions carefully \n 2. Answer all the question \n 3. Scores will be computed after the quiz \n 4. No Cheating!","RULES",JOptionPane.WARNING_MESSAGE);
        JOptionPane.showMessageDialog(null, "This Quiz consist of \n 1. Multiple Choice \n 2.Enumeration \n 3. True/False");
        JOptionPane.showMessageDialog(null,"Quiz #1: Enter the correct letter of the answer");

        // STRING OF QUESTIONS
        String[] quesJava = new String [] {"1) The JDK command to compile a class in the file Test.java is", "2)    Java was developed by_____."};


        String[] answers1 = new String[] {"A) java Test.java", "B) java Test","C) javac Test","D) javac Test.java"};
        int answer1 = JOptionPane.showOptionDialog(null, quesJava[0], "JAVA", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, answer1, answer1[0]);

            if (answer1== ???????????) // the answer is letter "D" but I don't know what will I put in here
            {
                score++;
            }

        String[] answer2 = new String[] {"A) IBM ", "B) Microsoft ","C) Sun Microsystem ","D) Oracle"};
        int answer2 = JOptionPane.showOptionDialog(null, quesJava[1], "JAVA", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, answer2, answer2[0]);
        {
            if (answer2== )
            {
                score++;
            }
        }

        JOptionPane.showMessageDialog(null,"your score is"+score);
    }


}

}

Aucun commentaire:

Enregistrer un commentaire