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
Re: How do I manage this data?
One solution could be a two-dimensional array, so:
Code:
String[][] answers = new String[2][5];
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