0

I want to design a language learning Android application where random set of questions are retrieved from the database and displayed to the user.

I have different type of questions such as multiple choice questions, fill in the blanks, matching the correct choice, arranging the words into a proper sentence and listening to audio and answering the comprehension questions.

How to store these different types of questions in the database and retrieved randomly and displayed to the user to be answered?

I am using SQLite.

Cœur
  • 37,241
  • 25
  • 195
  • 267
faz
  • 453
  • 2
  • 8
  • 15

3 Answers3

2

This is a pretty broad question and there are a lot of things you need to consider. For example, the modelling of your questions, and persistence -- storing them in the DB. I made a similar Android app a few years ago.

The first thing I suggest is working in incremental steps; things are much easier if you start out with, say, multiple-choice questions only (that all have four answers). Then once you have that working, add other types of questions.

For modelling your object domain, I suggest starting with a single base Question class. This can contain some common properties, like the unique ID, the name/shortname, perhaps some sort of difficulty metric.

After this, you can have sub-types of questions, such as a MultipleChoiceQuestion, a ShortAnswerQuestion, and an EssayQuestion. They may have other properties (like the list of possible answers for mutliple choice).

Mapping all this to a bunch of tables is not trivial. The usual method is one table per class; another option is one table with all the properties for all classes, and some sort of 'type' discriminator. I suggest the former, since it's a cleaner separation of attributes.

Finally, in terms of random, there are two approaches: random on the database level (more efficient, since it returns less data) or random on the application level. The difference is "hey database, get me N random questions" vs. "hey database, get me all the questions; hey application, pick N random questions."

To leverage the DB, you can use this answer here, where they use ORDER BY RANDOM() LIMIT N. I don't know about SQLite, but in SQL Server, with large data sets, this can be extremely slow; if you have a lot of questions, profile it and see if this is too slow for your app.

If you have a base Questionstable with all questions, this will work quite easily for you. If not, you may need to do something similar where you poll forAmultiple choice questions,Bshort answer questions, etc. whereA + B + ... = N` number of questions you want.

Community
  • 1
  • 1
ashes999
  • 9,925
  • 16
  • 73
  • 124
  • 1
    @faz since you marked this as accepted, can you clarify what you found useful out of it, and what needs improvement or more detailing? – ashes999 Feb 05 '14 at 14:47
0

The approach I use for this type of problem is to uniquely identify each of your rows. A sequence ID is fine.

Each time you go through the loop, place all of the IDs into an array structure. Each entry in the array has a random number and an ID into your SQLite table.

After you do this, sort the array and now you have randomly sequenced the questions. Process in order.

Thom
  • 14,013
  • 25
  • 105
  • 185
  • I think it can be done if all questions are same type. For example, if all questions are mcq, then i can load the relevant answers. But here i am having problem with storing different kind of questions and retrieving them randomly. – faz Feb 05 '14 at 14:25
  • How to handle different types of questions is a different problem altogether. You will want to put a question type on your question, then handle the different question types differently. None of that is hard, just takes a little doing. Ask a new question if you want to discuss. – Thom Feb 05 '14 at 14:30
0

Your question is too abstract, still trying to answer your question.

First of all, you will need to create a database which will contain a table that uniquely identifies your questions.

And then, you can fire the query as:

SELECT * FROM table ORDER BY RANDOM() LIMIT 1; which can be used for selecting a random row from sqlite table.

And then, simply code for displaying that question.

Chintan Soni
  • 24,761
  • 25
  • 106
  • 174