Nested Loops Lab: Quiz: Fall 2024
Learning Objective(s)
- Implement nested loops
- Work with a sequential text file
- Implement exceptions
Overview of the Program
Write a program to give a quiz
Specifics
- The program is to be called Quiz
- Get it to work correctly using "throws exception" before catching them. The final version must catch exceptions.
- The user is to input the name of the file that contains the quiz.
- Your program must work with the sample quiz in the lab folder
- The program should output the number of questions asked and the number of questions answered correctly.
- After each question, the program should inform the user if he/she answered it correctly.
- You must have one event controlled loop and one count controlled loop.
- There should be one constant for the number of possible answers to a give question. (Every question in a given file will have the same number of possible answers.)
- Be sure to close the file.
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 quiz (i.e. the file)? samplequiz
Question: What color is the sky?
A: blue
B: yellow
C: black
D: grey
Answer? A
Correct.
Question: What is 2 + 2?
A: 1
B: 2
C: 3
D: 4
Answer? B
Wrong. The answer was D.
You got 1 out of 2 questions.
You can also run a solution for this program if you want. See classroom instructions for more details.
Lab Hints
- Hint 1: A flowchart for the problem
- Hint 2: Dealing with exceptions: see class examples
- Hint 3: If you have trouble opening the file, make sure that file is in the same folder as the program is and you are in that folder in JGrasp
Submission
- Create a software development report
- For the system design, you may use my flowchart if it is the design of your program. Otherwise, you need to make your own.
- For testing report,
- adapt the testing form so that the input column could also include instructions to the tester
- test your loops well:
- Test for different number of questions
- Test for a different number of answers
- Test for different %'s of number correct
- Include the details of one data file. You can just describe the rest
- Once again, the expected output cannot be a cut/paste from the running of your program
- For the improvement section, specify how many points were lost from the last lab that you should not lose points for on this lab because you corrected the problem
- create a pdf document from your software development report
- create an empty zip folder
- place only Quiz.java and your pdf document into it
- submit the zip folder on canvas
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.
- Get the file name from command line arguments. This you must research on your own. There will be no help from any lab assistant or instructor or any other live human being to do this. Be sure to document the outside resource if you do this option
- Allow for the user to use upper or lower case when given their answer
- Save the program as QuizExtra.java and include it in the zip folder