Question: Java Assignment 3 Idea: We have all had to take quizzes, whether for fun or as a requirement (ex: this course). In this assignment you
Java Assignment 3
Idea: We have all had to take quizzes, whether for fun or as a requirement (ex: this course). In this assignment you will implement a simple multiple choice quiz, using good object-oriented programming style. The user will be shown some questions that he / she will answer. After completing all of the questions, the user will find out how many he / she got right and wrong. He / she will also then be shown the correct answers and the average scores for all users, followed by a sorted list of the questions. Note: Information on the individual players will not be stored. The main class must be named Quiz and should be stored in a file named Quiz.java. Execution Details: When your program is started it will read a number of questions from a text file. The name of the file must be entered on the command line when the program is executed. Each question will consist of the following parts: 1) The question itself, in sentence form on a single line 2) An integer, N, indicating how many answers are given (also on a single line) 3) The actual N answers, 1 per line 4) An integer, K, indicating which of the answers is correct (also on a single line) 5) An integer, T, indicating how many times this question was tried (also on a single line) 6) An integer, C, indicated how many times this question was answered correctly (also on a single line) There could be any number of questions in the file, and your program will not know how any in advance. Thus, you must be able to check for the end of the file in a reasonable way. You must read these questions into an ArrayList of type Question. All of your questions CANNOT have the same number of possible answers [e.g. the value for 2) above must be different in at least two of your questions]. When you first create your file, items 5) and 6) should be 0 for every question. However, as people take the quiz these values will be updated and saved back into the file. You must write and use class Question in a good object oriented way. More details on Question will be given in the Implementation Details and Hints. I will put a SAMPLE file of questions online, but for this assignment you are REQUIRED to make up your own question file with at least 5 questions in it. Once your questions have been read in you will display them to the user one at a time and allow the user to answer them by typing in the numbers of the correct answers. However, you should NOT show the user the answers and his/her results until the entire quiz has been completed. After each question has been answered, simply accept the answer and proceed to the next question (storing the user's guess within each Question object). Answers outside the valid range should be rejected (and user must re-enter). After all questions have been tried you must show the user his/her results in the following way: - For each item in the Question ArrayList, do the following Display the question to the user Display the correct answer to the user Display the user's guess back to the user Indicate whether the user got the question right or wrong - After all of the individual results have been displayed, show the user his / her overall score (percent of questions correct) - Next, show the following cumulative statistics: Times right, times wrong and percentage right for each question Easiest question and its percentage right Hardest question and its percentage right Before ending the program, update the question file to reflect the results from the current user. Make sure the format is exactly the same as it was, so the same file can be used multiple times in your program. Implementation Details and Hints: - You must write a class called Question to represent a single quiz question. This class must minimally include a String for the question itself, an array of Strings for the possible answers, an int to indicate the correct answer and two ints to store the number of times tried and number of times correct. Note that the array of Strings to store the possible answers must be sized in the constructor, since it can vary from question to question. You may find that you need additional instance variables as well. You will also need various methods in your class think about what access is needed and how it must be implemented. - You must store your Questions in an ArrayList and access the questions via the ArrayList. This ArrayList should NOT be within the Question class since the Question class represents a single Question. Rather it should be in your main (or perhaps another class if you prefer). - The file access for this program is again fairly straightforward. The file is formatted in such a way as to make the input and extraction of the data fairly simple. However, note that some of the data read in is String data and some is int data be careful to handle these types appropriately. - To find the easiest and hardest questions you will need to compare Questions based on their percentage right. Thus you will need an accessor in the Question class to return the percentage right for that question. - Don't forget to comment your code and to submit your Assignment Information Sheet with your other files. - Make sure you submit all of your files (including data files) so the TA can run your program. - To see an example of how your program execution might look, see the sample execution file in this directory.
___________________________________________________________________________________________________________________________________________________________
Sample Output:
Welcome to the Quiz Program! Good Luck! Question 0: How many licks does it take to get to the tootsie roll center of a tootsie pop? Answers: 0: one 1: two 2: three 3: four Your answer? (enter a number): -2 Your answer? (enter a number): 5 Your answer? (enter a number): 2 Question 1: What is your name? Answers: 0: Arthur, King of the Britons 1: Sir Lancelot the Brave 2: Sir Robin the Not-Quite-So-Brave-As-Sir Lancelot Your answer? (enter a number): 2 Question 2: Who's on first? Answers: 0: What 1: Why 2: Because 3: Who 4: I don't know Your answer? (enter a number): 3 Question 3: Which of the following is a terror of the fire swamp? Answers: 0: Lightning sand 1: Flame spurt 2: R.O.U.S. 3: All of the above Your answer? (enter a number): 1 Question 4: Who is the all-time greatest pilot? Answers: 0: Manfred von Richthofen 1: Chuck Yeager 2: Hiraku Sulu 3: Luke Skywalker 4: Kara Thrace 5: Charles Lindbergh Your answer? (enter a number): 4 Thanks for your answers! Here are your results: Question: How many licks does it take to get to the tootsie roll center of a tootsie pop? Answer: three Player Guess: three Result: CORRECT! Great Work! Question: What is your name? Answer: Arthur, King of the Britons Player Guess: Sir Robin the Not-Quite-So-Brave-As-Sir Lancelot Result: INCORRECT! Remember the answer for next time! Question: Who's on first? Answer: Who Player Guess: Who Result: CORRECT! Great Work! Question: Which of the following is a terror of the fire swamp? Answer: All of the above Player Guess: Flame spurt Result: INCORRECT! Remember the answer for next time! Question: Who is the all-time greatest pilot? Answer: Kara Thrace Player Guess: Kara Thrace Result: CORRECT! Great Work! Your overall performance was: Right: 3 Wrong: 2 Pct: 60% Here are some cumulative statistics: Question: How many licks does it take to get to the tootsie roll center of a tootsie pop? Times Tried: 14 Times Correct: 5 Percent Correct: 35.7% Question: What is your name? Times Tried: 14 Times Correct: 6 Percent Correct: 42.9% Question: Who's on first? Times Tried: 14 Times Correct: 7 Percent Correct: 50.0% Question: Which of the following is a terror of the fire swamp? Times Tried: 14 Times Correct: 4 Percent Correct: 28.6% Question: Who is the all-time greatest pilot? Times Tried: 14 Times Correct: 9 Percent Correct: 64.3% Easiest Question: Question: Who is the all-time greatest pilot? Times Tried: 14 Times Correct: 9 Percent Correct: 64.3% Hardest Question: Question: Which of the following is a terror of the fire swamp? Times Tried: 14 Times Correct: 4 Percent Correct: 28.6% assig3 > cat sample.txt How many licks does it take to get to the tootsie roll center of a tootsie pop? 4 one two three four 2 14 5 What is your name? 3 Arthur, King of the Britons Sir Lancelot the Brave Sir Robin the Not-Quite-So-Brave-As-Sir Lancelot 0 14 6 Who's on first? 5 What Why Because Who I don't know 3 14 7 Which of the following is a terror of the fire swamp? 4 Lightning sand Flame spurt R.O.U.S. All of the above 3 14 4 Who is the all-time greatest pilot? 6 Manfred von Richthofen Chuck Yeager Hiraku Sulu Luke Skywalker Kara Thrace Charles Lindbergh 4 14 9
___________________________________________________________________________________________________________________________________________________________
Sample File:
How many licks does it take to get to the tootsie roll center of a tootsie pop? 4 one two three four 2 14 5 What is your name? 3 Arthur, King of the Britons Sir Lancelot the Brave Sir Robin the Not-Quite-So-Brave-As-Sir Lancelot 0 14 6 Who's on first? 5 What Why Because Who I don't know 3 14 7 Which of the following is a terror of the fire swamp? 4 Lightning sand Flame spurt R.O.U.S. All of the above 3 14 4 Who is the all-time greatest pilot? 6 Manfred von Richthofen Chuck Yeager Hiraku Sulu Luke Skywalker Kara Thrace Charles Lindbergh 4 14 9
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
