Results 1 to 3 of 3
  1. #1
    Codeless is offline Member
    Join Date
    Nov 2010
    Posts
    37
    Rep Power
    0

    Default How do I manage this data?

    I'm creating a quiz where I am presented with a random question then when I press something the answer appears.

    So I want to read in a file full of questions and answers.

    questions start with q: and answers start with a:.

    now I could quite easily create two arrays and the element indexes would line up appropriately... then I can use that data in my quiz.

    but what if I don't have a one-to-one relationship?

    what if my file is like this

    Q: questionOne
    A: answer1/1
    Q: questionTwo
    A1: answer1/3
    A2: answer2/3
    A3: answer3/3

    if more than one answer can be associated with a question then my arrays obviously wont work... how do I read in a file like this and keep the information for each question?

    thanks

  2. #2
    Nouish is offline Member
    Join Date
    Dec 2012
    Posts
    12
    Rep Power
    0

    Default Re: How do I manage this data?

    One solution could be a two-dimensional array, so:

    Java Code:
    String[][] answers = new String[2][5];
    Last edited by Nouish; 12-29-2012 at 06:07 AM.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,202
    Rep Power
    19

    Default Re: How do I manage this data?

    Java is an object oriented language. Parallel arrays are a symptom of object denial.

    Create a Question class that holds an array or java.util.List of answers.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. how can i manage working day hours
    By davidmuleiro in forum New To Java
    Replies: 1
    Last Post: 08-14-2012, 07:40 AM
  2. How to Manage different JPanel in an application
    By jfabian in forum New To Java
    Replies: 2
    Last Post: 07-30-2012, 04:20 AM
  3. Best way to manage images?
    By sgthale in forum New To Java
    Replies: 3
    Last Post: 09-30-2011, 02:11 AM
  4. Program to manage books
    By datreta in forum New To Java
    Replies: 6
    Last Post: 12-16-2010, 09:30 AM
  5. can't manage to get this
    By mollentze in forum New To Java
    Replies: 3
    Last Post: 01-11-2008, 11:03 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •