Lab 4

This program will read in a set of True-False questions from the questions.dat file (see file description below) and present them to the user. The user will answer each question. They navigate through the questions using the Next button.

After all questions have been answered, the user's score is displayed in a dialog box.

The Question File

The question file contains the following structure:

File: questions.dat
Field DescriptionData TypeComments
question IDintid for a question
question textStringthe actual text for the question
answerbooleanthe answer to the question (true or false)

Records are delimited with the new-line characters. Fields are delimited with the pipe | symbol.

There can be any number of questions in the file.

You can create your question file by hand using a text editor. An example file might look like this:

1|James Gosling was named a Companion of the Order of Canada.|false
2|Paul Toms once had bright blue hair.|true
3|Sheridan is building a new campus in Mississauga.|true
4|Smalltalk was the first object-oriented language.|false
5|Java FX is Sun's answer to Flash and Silverlight.|true

Your data file must have at least 5 questions.

File Handling Hints:
Keep the file open while the program is running! Open the connection to the file in your constructor method, then close it just before the user exits the program (don't forget to check first and make sure the stream isn't a null object). Then, in your next button, you simply need to read the next record in the file until you run out of records.

The Quiz Program

The Quiz GUI

The Quiz Gui file contains the Swing GUI for the program that displays a quiz to the user.

The interface consists of fields that display a question, including a set of radio buttons that allow the user to guess the correct answer to the question. Once the user answers a question, they can click the Next button to view the next question. After all questions have been accessed and answered, results are displayed in a message dialog.

HINT: To get the question to word wrap, use a text area. Make the text area non-editable and set it's background to the JFrame's background colour.

The user exits the program by using the Exit button.

Submission

Your submission must follow all the submission requirements outlined in the Submission Standards.

Your classes and all public methods must be documented using the javadoc standard. You do not need to compile or submit your javadocs.

If you do not follow the instructions detailed above, your submission will not be accepted. DO NOT simply ZIP/RAR your entire project file and send it to me. I will not sort through your directories to find your source code - I will simply give you a grade of 0.

To submit your completed assignment, log into the Course Evaluation Index and use the "Submit Assignment" link. Submit this assignment as "Lab 4".

Evaluation

Your submission will be evaluated based on the following criteria:

Efficient Code: Program uses variables where and only when necessary; program doesn't define variables that are never used, nor does it use too many variables for unnecessary tasks. Program structures such as IFs and loops do not perform any unnecessary tasks, evaluations, or iterations. Redunant code is eliminated using methods.

Functionality: The GUI includes all the components that were required (see specs in bulletin board) and appears professional, neat, and intuitive. The components do not shift or resize unattractively when the user resizes or maximizes the screen. Each component or set of components performs as specified above.

Programming Style: proper indentation and spacing, use of comments/documentation; all identifiers are descriptive and valid; varibles are defined with appropriate types and converted when required. Component variable names use the proper prefixes (i.e. cmd, txt, lbl)

Other: all instructions regarding submissions and program specifications have been followed; submission was completed and submitted as requested in a timely fashion; techniques discussed in class have been used.

Bonus Marks

One addition you can implement for bonus marks is the ability to open different question files. You might include a menu with a File option that allows the user to select a question file using a JFileDialog component. Since you can't control whether or not the user chooses a file in the valid format for questions, you will need to make sure your code that reads the file contains appropriate exception handling.

Another idea is to add a Reset button that takes the user back to the start of the quiz (this will involve closing the file stream and re-opening it again, for instance).

If you have other ideas, run them by me before you implement them.