java - Best way to store temporary QuestionID-AnswerID data -
i'm developing quiz app , want find efficient way save user's answers.
each quiz has 30 questions , need save is: questionnumber
, questionid
, answerid
, either answer correct or not.
i thought array solution. example:
each row represents question (questionnumber
). first column represents questionid
, second answerid
. third column contain either 0
(incorrect) or 1
(correct).
the third column (correct) needed sum number of correct answers (it's faster sum third column instead of checking each answer time).
this isn't sql table - info temporary , destroyed user finishes quiz.
i want know if have other solutions, maybe better.
thank you!
why not class?
class answer { private int questionid; private int answerid; private boolean correct; public answer(int questionid, int answerid, boolean correct) { this.questionid = questionid; this.answerid = answerid; this.correct = correct; } }
and arraylist
list<answer> answers = new arraylist<answer>();
then use
answer answer = new answer(1, 2, true); answers.add(answer);
with array need fix array size every time add question arraylist can add questions want without care array size.
anyway, if questions 30 can create array without problems.
about performances, don't see problems speed/memory.
Comments
Post a Comment