computer science

posted by .

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?

  • computer science -

    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.

  • computer science -

    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:" );
    //creating a frame
    JFrame frame = new JFrame();
    frame.setTitle ("Are you Smarter than a 5th Grader");

    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");

    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();

    //adding radiobutton to the panel.

    //Display the window.


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


Respond to this Question

First Name
School Subject
Your Answer

Similar Questions

  1. computer

    this isnt really a school question but i have a question about the sun wouldnt load any of my games using it but whenever i deleted it and using the regular java...its working doesnt make any sense...please i hope …
  2. Computer Science-Java

    Hi, I have to prompt a user to input a password and have to verify whether or not it is a single word. How would I do something like?
  3. computer

    can u help me in making a "quiz" wid reference by using u help me as soon as possble
  4. computer science

    I have a project due May 17. I have to create a math game using a GUI/Menu. The game has to give the user the option to chosse between which subject they would like to work on: adding, subtracting, dividing, multiplying integers; adding, …
  5. comp sci

    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?
  6. computer science

    I need to write a program that ask the student to enter an answer to a math problem. The user should enter two values, one at a time, and then ask for an answer. The program should display if the entered answer is correct or not and …
  7. Web Scripting

    I'm using actionscript. when you press the mouse, you can draw (using a rectangle) and when you click the mouse it changes colors. What I need to do is have buttons so that a user can click on the button to choose the color they want. …
  8. Java programming

    can u give me some example of withdrawal money program using array to store ten information of user. including the attributes: (i) Name of the depositor (ii) Account number (iii) Type of account (iv) Balance amount And the methods: …
  9. Computer Science Java

    Alright I have these strings String domain1 = ". com"; String domain2 = ". edu"; String domain3 = ". org"; I want to make sure that when the user puts in their username (their email) that the domain will be the last four characters. …
  10. java programming

    the learner is asked to write a program using java with user input that caculate and displays, the number of months it will take the user to save an amount of money. the user must enter the

More Similar Questions