Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struggling to OOP data model a "multiple choice exam"

 
James Elsey
Ranch Hand
Posts: 228
Android IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I'm trying to create an application which is essentially a multiple choice simulator. There will be a "Quiz", the quiz will have a number of questions which I'll refer to a list of "QuizItem"s.

Each "QuizItem" has a "Question", and that question has a number of "Answers".

Here is what I've worked out so far..




I'm not convinced that datamodel is entirely correct, and I'm struggling to find resources on the net, or at least any pointers with this type of data model.

Would it be best to have the QuizItem only aware of answers, and have the answers depend on a Question?

I know this should be simple, but please help!

Thanks
 
Lanny Gilbert
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd remove QuizItem entirely.. Now, you have a quiz that consists of a list of Questions. each Question has a questionText (the actual question) and a list of
answers. Does this look like what you want???



public class Quiz
{
private int id;
private List<Question> questionList;

//accessors
}

public class Question
{
private int id;
private String questionText;
private List<Answer> answers;

//accessors
}

public class Answer
{
private int id;
private boolean isCorrect;
private boolean isUserSelected;
private String answerText;

//accessors
}
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I think you are mixing up the question data - which should be the same for all users taking the exam - with the individual user results.

The exam - consisting of a list of Questions - should not be affected by individual user actions.

A single user should have a Serializable object which stores his/her state of taking the exam - link to the Question set, current question number, answers, graded/not graded, etc etc. I say Serializable because then you can store the user's current state and recover it.

Based on my extensive experience with exam simulators, try to make it easy for exam authors to create question scripts. Personally I ended up with XML for maximum flexibility.

Bill


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic