Senior Capstone Project
By: Mac Barrett
I used .txt files because I did not feel like a fully-fledged database would be very helpful seeing as how simple it would end up being. All that I really needed was to read the questions from somewhere, parse them correctly, and move them to an object that ensure's it is a simple process to select the next item. A CSV style .txt file is perfect for this purpose considering the built in str.split() function Java has built in. Using this method, storing questions need not be more complicated than storing a single number.
As for the actual contents of these files, they are seperated by question category and formatted in a CSV style. One question and its answers take up a line, with the correct answer directly following the question, each value seperated by a comma. This convention allows for the authentication of correct answers later. The rough format is as follows:
It isn't just a queue! It is actually an ArrayList of six seperate Queue's that store Strings and seperated by the question's category. The full Java declaration is "ArrayList<Queue<String>>" which is a little gross looking, but it is the perfect storage system for my methods.
A queue is useful for my purposes because it makes it extremely easy to do many of the required features that a game like this requires:
Furthermore, containing all six of these queues in an ArrayList makes it very easy to do all of the above things dynamically and do other things based upon user input.
At the beginning of each game, this data structure is constructed by parsing each .txt file in the "questions" folder of the directory adding each readLine() to the queue. Once it reaches the end of the first file, it then adds the temporary queue to the ArrayList, deletes the temporary queue, and starts over for the next .txt file. After all of the queues have been constructed, the main server shuffles the order of the strings inside each queue--the string isn't split until after it has been selected.