By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,144 Members | 880 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,144 IT Pros & Developers. It's quick & easy.

How to create Java based quiz system? need ideas

P: 3
Hello everyone,

One of my course works is to implement a java based quiz system. the program consists of two modules one for the teacher to create, set questions , answers and the number of questions to be published, and the other one is to allow the student to run the quiz. the data for the quiz is stored in text files and the correct answers are encrypted. everytime the students take a quiz the result has to be stored and a report containing the number of questions were answered correctly and the number of questions were answered incorrectly to be included for the teacher to view later.

Would really appreciate some suggestions regarding the following questions.

1. I am not entirly sure what data structure to use in order to link each question with the right answer?

2. Whether to store the correct answers in a seperate file or in the same file as the questions and their associated answers?

3. How to Structure the database file?

Thanks for all your replys in advance.
Nov 20 '07 #1
Share this Question
Share on Google+
5 Replies


Expert 100+
P: 785
Hello everyone,

One of my course works is to implement a java based quiz system. the program consists of two modules one for the teacher to create, set questions , answers and the number of questions to be published, and the other one is to allow the student to run the quiz. the data for the quiz is stored in text files and the correct answers are encrypted. everytime the students take a quiz the result has to be stored and a report containing the number of questions were answered correctly and the number of questions were answered incorrectly to be included for the teacher to view later.

Would really appreciate some suggestions regarding the following questions.

1. I am not entirly sure what data structure to use in order to link each question with the right answer?

2. Whether to store the correct answers in a seperate file or in the same file as the questions and their associated answers?

3. How to Structure the database file?

Thanks for all your replys in advance.
1.) you can use a Vector.
Expand|Select|Wrap|Line Numbers
  1. Vector answers = new Vector();
  2. Vector questions= new Vector();
  3. questions.add("question1");
  4. answers.add("answer1");
  5. questions.add("question2");
  6. answers.add("answer2");
  7. questions.add("question3");
  8. answers.add("answer3");
  9. ...
  10. System.out.println("The first answer is: " + answers .elementAt(0));
  11. System.out.println("The second question is: " + questions.elementAt(1));
You could also try with Properties:
Expand|Select|Wrap|Line Numbers
  1. Properties questionsAndAnswers = new Properties();
  2. questionsAndAnswers.setProperty("question1", "answer1");
  3. questionsAndAnswers.setProperty("question2", "answer2");
  4. questionsAndAnswers.setProperty("question3", "answer3");
  5. ...
  6. System.out.println("The first answer is: " + questionsAndAnswers.getProperty("question1"));
or you can use string-arrays:
Expand|Select|Wrap|Line Numbers
  1. String [][] questionsAndAnswers = {{"question1", "answer1"}, {"question2", "answer2"}, {"question3", "answer3"}};
  2. System.out.println("The first answer is: " + questionsAndAnswers[0][1]);
2.) store them in a separate file. One file for the original question and answer. And one file for each student for all the answers a student has given.
If you mix all data in one file, you will have problems if you want to modify/delete some data later on.

3.) Use XML. Then here is already a java-method that you can use to read and save all the data for you. (read about SAX and DOM). XML is industrial standard. A lot of programs can read it or create it and so you can use the data for everything. You can display the file directly into your browser, convert it to a table for a database, edit it comfortably etc.
For example:
...
Expand|Select|Wrap|Line Numbers
  1. <student>
  2. <name>newbie</name>
  3. <answerList>
  4.     <answer>answer1</answer>
  5.     <answer>answer2</answer>
  6.     <answer>answer3</answer>
  7. </answerList>
  8. </student>
4.) Now I have a question:
It's not quite clear why you post this question in this forum if this task was given by a teacher for your programming course. If others solve it for you, then you don't learn. I hope the answers gave to you are getting you started. But try yourself as much as you can. Next time, post some code from your own tries where you got stuck. Have you tried already or just copied the task onto the forum without trying or thinking/reading yourself?
Nov 20 '07 #2

10K+
P: 13,264
...

3. How to Structure the database file?

...
What database file?

1.) you can use a Vector.
Vectors are not the right approach here. Besides they being old, they do not store a mapping relationship. A Map is much better.
Nov 20 '07 #3

Expert 10K+
P: 11,448
Are those questions multiple choice questions (easy) or are they supposed to
be 'open end' questions (very difficult)?

kind regards,

Jos
Nov 20 '07 #4

P: 3
Thanks for all your replys .

By the database i mean the test files one of which holds the quizzes and one of which is holds the correct answers and has to be encrypted.

The questions are multi-choice with four answers to each question and one correct answer.

I am kinda thinking towards array list , What do you think?

Many thanks
Nov 27 '07 #5

P: 3
1.) you can use a Vector.
Expand|Select|Wrap|Line Numbers
  1. Vector answers = new Vector();
  2. Vector questions= new Vector();
  3. questions.add("question1");
  4. answers.add("answer1");
  5. questions.add("question2");
  6. answers.add("answer2");
  7. questions.add("question3");
  8. answers.add("answer3");
  9. ...
  10. System.out.println("The first answer is: " + answers .elementAt(0));
  11. System.out.println("The second question is: " + questions.elementAt(1));
You could also try with Properties:
Expand|Select|Wrap|Line Numbers
  1. Properties questionsAndAnswers = new Properties();
  2. questionsAndAnswers.setProperty("question1", "answer1");
  3. questionsAndAnswers.setProperty("question2", "answer2");
  4. questionsAndAnswers.setProperty("question3", "answer3");
  5. ...
  6. System.out.println("The first answer is: " + questionsAndAnswers.getProperty("question1"));
or you can use string-arrays:
Expand|Select|Wrap|Line Numbers
  1. String [][] questionsAndAnswers = {{"question1", "answer1"}, {"question2", "answer2"}, {"question3", "answer3"}};
  2. System.out.println("The first answer is: " + questionsAndAnswers[0][1]);
2.) store them in a separate file. One file for the original question and answer. And one file for each student for all the answers a student has given.
If you mix all data in one file, you will have problems if you want to modify/delete some data later on.

3.) Use XML. Then here is already a java-method that you can use to read and save all the data for you. (read about SAX and DOM). XML is industrial standard. A lot of programs can read it or create it and so you can use the data for everything. You can display the file directly into your browser, convert it to a table for a database, edit it comfortably etc.
For example:
...
Expand|Select|Wrap|Line Numbers
  1. <student>
  2. <name>newbie</name>
  3. <answerList>
  4.     <answer>answer1</answer>
  5.     <answer>answer2</answer>
  6.     <answer>answer3</answer>
  7. </answerList>
  8. </student>
4.) Now I have a question:
It's not quite clear why you post this question in this forum if this task was given by a teacher for your programming course. If others solve it for you, then you don't learn. I hope the answers gave to you are getting you started. But try yourself as much as you can. Next time, post some code from your own tries where you got stuck. Have you tried already or just copied the task onto the forum without trying or thinking/reading yourself?




Thanks alot for your suggestions chaarmann,

I have been trying but I would like to use the best suited data structure before submitting it , I have been thinking about using XML but not allowed to do so , I have been trying with array list and it looks promising , I agree with what you are saying trying and learning from it.
Nov 27 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.