Exceptions: Quiz program using exceptions: Fall 2023
Learning Objective(s)
- Continue to improve methods
- Continue to work with files
- Become more confident in programming skills
- Simple exception handling
Overview of the Program
Create a program to give multiple choice quizzes to the user.
Specifics
- The program should be called Quizzer
- There should be at least two constants:
- A string constant represent the word used to quit the program
- A boolean constant representing correct
- All IO exceptions should be caught, not thrown
- The program should continue to give quizzes to the user until done is entered.
- For each quiz, there are a number of multiple questions with 4 possible answers each.
- For each quiz, the program should inform how many questions were answered and how many were answered correctly.
- The only I/O allowed in the main method should be to get the name of the file containing the next quiz (along with the associated prompt)
- You should have one method that will process an entire quiz. The only I/O it should do is to open and close the file and report on the entire quiz.
- You should have a method that asks one question. It asks the question (including giving the possible answers), gets the answer from the user, reports to the user if it is correct and returns that status.
- You should have another method that ensures that the user only inputs a, b, c, or d. It should return what was inputted correctly.
Sample dialogue
Below is a sample dialogue. Your output can vary somewhat as long as the required data is nicely displayed
What is the name of the file with the quiz?
(done means quitting)
questions
What color is the sky?
a red
b blue
c green
d grey
c
Wrong
What state are we in?
a Hawaii
b Indiana
c confusion
d California
b
Correct!
You got 1 right out of 2.
What is the name of the next quiz (done to quit)?
done
You can also run a solution for this program if you want. See classroom instructions for more details.
Submission
- Create your SDR.
- In Lessons Learned, include a discussion on how things you feel more comfortable with.
- Your testing should include at least 2 different types of errors and ensure that every line of code is executed at least once. Add copies of your files that you used (with appropriate links back to the test cases) at the end of the report. Try to put them in columns to save space. You might want to have different sets of files for some of the different tests.
- If you used any hints, be sure to indicate that in the Outside Resources Used section
- Convert your SDR into a pdf document
- Create an empty zip folder
- Place your java file and pdf document in it.
- Submit the zip folder on canvas
Hints
- Algorithm hint for main
- Algorithm hint for giving the quiz
- Algorithm hint for asking a question
- Algorithm hint for ensuring a valid answer from the user
- Handling exceptions
Optional improvements
Optional improvements should ONLY be worked on once the program is completing working. In addition, the work is to be done on your own with little if any help for lab assistants or the instructor.
- Gather statistics across all quizzed given such as the average score, total correct, etc.
- Use command line arguments for the names of the quizzes