computer science

hi i am using java to make a quiz... i am using JFrame and have radio buttons so the user can give his answer. For example:

Who co-stared with Leonardo Dicaprio in the movie Titanic?
Kate winslett.
No i have a radio button in front of it and i have four options. I want to tell the user if its a right or wrong. I wanna compare compare the answwer with the radiobutton he clicked? how do i do that since they are incomparable types?

  1. 👍
  2. 👎
  3. 👁
  1. The radio buttons don't really care what you wrote to the user. It only knows from you what to do if the user picks button 1, or 2, or 3, etc.
    You should have an array (if you have many questions) to indicate which answer is correct for which question. Then program the messages accordingly.

    1. 👍
    2. 👎
  2. import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;

    class Quiz

    /* Student Assignment Submission Form
    ==================================
    I declare that the attached assignment is wholly my own work in accordance with Sheridan Academic Policy.
    No part of this assignment has been copied manually or electronically from any other source (including web sites)
    or distributed to other students.
    My name is: Gaurav Sharma
    */
    {

    public static void main(String[] args)
    {
    String userName;


    int correct;
    int incorrect;
    int percentage;
    JOptionPane.showMessageDialog (null, "Are You Smarter Than a 5th Grader?"); // Creating a welcome Dialog Box.
    userName =JOptionPane.showInputDialog (null, "Greetings User. " +"Enter your name:" );
    //Questions.
    //creating a frame
    JFrame frame = new JFrame();
    frame.setTitle ("Are you Smarter than a 5th Grader");
    frame.setSize(1000,550);
    frame.setLocationRelativeTo(null);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JLabel quest1 = new JLabel("Who co-stared with Leonardo Dicaprio in the movie Titanic?",SwingConstants.CENTER);
    quest1.setPreferredSize(new Dimension(400, 20));




    //creating a panel
    JPanel panel = new JPanel();
    //creating a RadioButton.
    //radio buttons for first quest.

    JRadioButton r1 = new JRadioButton("KateWinslett");
    r1.setText("KateWinslett");

    r1.setActionCommand("KateWinslett");
    JRadioButton r2 = new JRadioButton("Tom Cruise");
    r2.setText("Tom Cruise");
    JRadioButton r3 = new JRadioButton("Julia Roberts");
    r3.setText("Julia Roberts");
    JRadioButton r4 = new JRadioButton("Osama Bin Laden");
    r4.setText("Osama Bin Laden");
    //creating a button group.
    ButtonGroup group= new ButtonGroup();
    group.add(r1);
    group.add(r2);
    group.add(r3);
    group.add(r4);


    //adding radiobutton to the panel.
    panel.add(quest1);
    panel.add(r1);
    panel.add(r2);
    panel.add(r3);
    panel.add(r4);

    //Display the window.

    frame.getContentPane().add(panel);
    frame.pack();
    frame.setVisible(true);


    if (e.getSource()== "Kate Winslett")
    {
    JOptionPane.showMessageDialog (null, "Are You Smarter Than a 5th Grader?");
    }


    }
    }

    1. 👍
    2. 👎

Respond to this Question

First Name

Your Response

Similar Questions

  1. Physics

    Radio amateurs are permitted to communicate on the "10 meter band." What frequency of radio waves corresponds to a wavelengthy of 20m? (The speed of radio wave is 3.00 x 10(8)m/s). Can you help me with setting up the formula?

  2. Connexus math

    Hello everybody. I have test answers to the connexus quiz on 7th-grade math. Here They are. 1.C 2. D 3.A 4.B 5.B 6.A 7.A 8.D Quiz is on Wednesday. Ciao!

  3. chem

    An FM radio station broadcasts at 97.4 MHz. Calculate the wavelength of the corresponding radio waves.

  4. Algebra 2

    Mrs. Jones algebra 2 class scored very well on yesterday's quiz. With one exception, everyone received an A. Within how many standard deviations from the mean do all the quiz grades fall ? Ó =3.1 95,

  1. math

    Tim wants his mean (average) quiz score in history class to be 90. His first 3 quiz scores were 86, 92, and 94. What score should he make on the 4th quiz in order to have a mean (average) quiz score of exactly 90? I really need

  2. Chemistry

    SO CONFUSED PLEASE HELP!!! A certain radio wave has a wavelength of 7 inches. a. convert the wavelength of this radio wave into meters. (1 meter = 39.37) b. find the frequency of this radio wave.

  3. math

    a radio station broadcasts at a frequency of 590,000 . What is the wavelength of the radio waves?

  4. statistic and probability

    There are two independent multiple-choice quizzes where quiz 1 has eight questions and quiz 2 has 15 questions. Each question in the first quiz has four choices and each question in the second quiz has five choices. Suppose a

  1. Statistic

    There are two independent multiple-choice quizzes where quiz 1 has eight questions and quiz 2 has 15 questions. Each question in the first quiz has four choices and each question in the second quiz has five choices. Suppose a

  2. Language Arts 6

    2.8.2 - Quiz: Comparing Prose and Poetry Quiz Read the excerpt from "If" by Rudyard Kipling. If you can make one heap of all your winnings And risk it on one turn of pitch-and-toss, And lose, and start again at your beginnings And

  3. Science

    I was so confused by this question!! Any advice?? Suppose at a concert a singer’s voice is a radio broadcast all the wave around the world before reaching the radio you hold to your ear. This takes 1/8 seconds. If you’re

  4. Programming Java

    I am learning Java in programming right now. I need to write a program that should have an output like this: The program says "Type ten names". Then ten names sould be typed a person. Then the program chooses a random name from

You can view more similar questions or ask a new question.