#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    2
    Rep Power
    0

    Help with Simple Quiz Program


    I am trying to make a basic quiz application, and am very new to Java programming. So far I have it set so that the question being asked by the quiz, and all of the answers are variables. The one that is correct is labeled correct. I want to have it set so that each of the possible answers (it is a four button multiple choice) is assigned one of the possible answers randomly.
    Example:
    String question1 = "How many inches are in a foot?";
    String incorrect1 = "4";
    String incorrect2 = "36";
    String incorrect3 = "24";
    String correct = "12;

    How would I have it set up so that the program output could look like this...:

    How many inches are in a foot?
    a) 12
    b)4
    c)24
    d)36

    ...or this...:

    How many inches are in a foot?
    a)24
    b)36
    c)12
    d)4

    ... changing every time I run it?

    The rest of the program works so far, just to let you know, I have tested it several times.

    And for the record, I have a placeholder for each answer that I then assign one of the answer variables.
    i.e.
    answer1.setText(incorrect1);
  2. #2
  3. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Feb 2004
    Location
    Mobile, Alabama
    Posts
    4,022
    Rep Power
    1285
    I would create a class definition where the instance variables are either two arrays, one with questions, and the other with answers, or a Map where the keys are questions, and the values are answers.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    2
    Rep Power
    0
    Originally Posted by bullet
    I would create a class definition where the instance variables are either two arrays, one with questions, and the other with answers, or a Map where the keys are questions, and the values are answers.
    But there are 4 answers and only one question, so how would this work? I wouldn't want random answers to be assigned to the question itself, I have radio buttons set up for each of the answers to be assigned to. This way, the user of the program can press the button and it will say if their answer is correct or not.
  6. #4
  7. Java Junkie
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Feb 2004
    Location
    Mobile, Alabama
    Posts
    4,022
    Rep Power
    1285
    Originally Posted by TheDarkasDay
    But there are 4 answers and only one question, so how would this work? I wouldn't want random answers to be assigned to the question itself, I have radio buttons set up for each of the answers to be assigned to. This way, the user of the program can press the button and it will say if their answer is correct or not.
    I'm sorry. I misunderstood. I would have an instance variable with the answer, and an array of incorrect choices. Then you could have a method that randomly displays them.

IMN logo majestic logo threadwatch logo seochat tools logo