+ 2

How to implement output and input file in Java to save a quiz state to continue playing later after a break?

I have a movie quiz in Java that has arrays, Abstraction Data Types, loops within loops, and keeps score for correct answers. Not sure how to implement this: saving the quiz state to an output file format and also importing that file to continue with the quiz later without losing the score and carry on from middle of the quiz. Still new to programming btw, only been coding 2 months ☺️

14th Nov 2018, 7:23 PM
Moe
Moe - avatar
3 ответов
+ 1
Great job :D Now how to create a save file, i assume the quiz question and answer are hardcoded or saved in file, and the order are randomized each time users play. Now the important data are the question order, which question is the user at, and user's right answers. Add some more if you think its necessary. Now wrap those up in easy-to-format string you can use your own structure or use json or xml. But i kinda recomend to use json using external library like GSON or org.json, so you can easily get the result as json string. Last thing you need to do is write it somewhere. for the loading part the reason i recomend to use json (or xml if you wanted to) is you also can easily recreate the object back using the given string. after you have the data you can start the quiz ande assign the data back
14th Nov 2018, 11:42 PM
Taste
Taste - avatar
+ 1
Taste thanks! And no the questions are not randomised at all always the same 20 questions in the same order. So I guess this makes it simpler to implement?
14th Nov 2018, 11:45 PM
Moe
Moe - avatar
0
Yes it should be simpler
14th Nov 2018, 11:46 PM
Taste
Taste - avatar