As described in the handout for Part 1, the overall aim of the assignment is to develop a program to administer a quiz test.
In Part 1, you have implemented the classes to represent the quiz questions and answers. You have also written programs to test these classes. In particular, you have written a program to read a number of questions from a text file, administer the questions, obtain the answers, and print out the answer.
Building on the work that you have done for Part 1, in this Part 2, you are required to do the tasks described below.
Besides the information given in the tasks below, please refer to Part 1 of the Assignment for any information you need.
Modify the classes QuizQuestion and QuizAnswer and their subclasses to use ArrayList in- stead of array whenever you need to maintain a collection.
Modify the QuizQuestionTester program from Part 1 to test your new classes.
Note: Even if you have used ArrayList for Part 1, you still need to submit all the files listed above.
(For Tasks 2 and 3, you must also use ArrayList whenever you need to maintain collections.)
Write a menu program called QuizMenu. The program displays the menu with the options shown below:
========
Options:
========
R: Read question details from a text file
A: Administer the quiz test
F: Administer the quiz test with option to quit
D: Display the answers on the scr
W: Write the answers to a text file
Q: Quit
Please select an option:
Other than the minimum required for the program to compile, no exception handling is required for this task.
Option R. The program asks for the name of the text file (e.g. Quiz1.txt) and read the ques- tions from this file. The file name (to be entered) includes the file extension. The file format is exactly as described in Part 1.
Option A. The way the program administers the quiz questions and obtains the answers is ex- actly as described in Part 1.
Option F. (F stands for Flexible administration of the quiz test). With this option, after answering a quiz question, the user will be asked if he/she wants to continue or not. If the user chooses to quit early, option D is still available to display the results of the questions has been answered. The behavior of the program is illustrated with a sample run below:
========
Options:
========
R: Read question details from a text file
A: Administer the quiz test
F: Administer the quiz test with option to quit
D: Display the answers on the screen
W: Write the answers to a text file
Q: Quit
Please Select an option: f
Question 1
try/catch blocks can be nested.
Type true or false: true
Do you want to continue? (y/n): y
Question 2
ArithmeticException is an _____ exception. Fill in the blank.
Type your answer: unchecked
Do you want to continue? (y/n): n
========
Options:
========
R: Read question details from a text file
A: Administer the quiz test
F: Administer the quiz test with option to quit
D: Display the answers on the screen
W: Write the answers to a text file
Q: Quit
Please Select an option:
Option D. The way the program displays the answer is illustrated by the example below:
QUESTION 1:
A checked exception must be caught or declared.
True or false?
Your answer is: true
It is correct.
QUESTION 2:
What is the keyword used to declare a class to be a subclass of another class?
a) implements
b) extends
c) subclass
d) interface
Your answer is: c
It is incorrect.
The correct answer is: b
Number of questions: 5
Number of answers: 2
Number of correct answers: 1
Number of incorrect answers: 1
As illustrated above, the display of the result of a quiz test ends with four lines of summary.
Option W. Theprogramasksforthenameofthefiletosavetheresultto(e.g. Quiz1Result.txt). The information to be written and the format are exactly as for displaying the result on the screen.
Once we start the menu program and take a few options, we do not want the program to crash.
For this task, you are required to enhance the program to achieve this objective. More specifically, the program is made robust in the following sense:
when the program carries out the operation required for an option, if some exceptional condition arises, this operation is aborted but the program itself does not crash. Thus, all the work up to that point is preserved and further operations, if appropriate, can be taken.
Make a copy of the previous menu program and call it QuizMenuRobust.java. Modify it to make it robust as described above.
Refer to the Tower of Hanoi problem covered in the lectures. The following program is written to find the number of moves it takes to move n discs (n = 1 to 64).
public class IntTowerMoves
{
public static int moves(int numberOfDiscs)
{
if (numberOfDiscs == 1)
return 1;
else
return 1 + 2 * moves(numberOfDiscs - 1);
}
public static void main(String [] args)
{
for(int n = 1; n <= 64; n++)
System.out.printf("%3dt%,dn", n, moves(n));
}
}
Run it and you will see that when n = 32, the output is -1, because the number of moves is too big for int (overflow).
Let us try to use long for number of moves as in the program below:
public class LongTowerMoves
{
public static long moves(int numberOfDiscs)
{
if (numberOfDiscs == 1)
return 1;
else
return 1 + 2 * moves(numberOfDiscs - 1);
}
public static void main(String [] args)
{
for(int n = 1; n <= 64; n++)
System.out.printf("%3dt%,dn", n, moves(n));
}
}
With this new version, when n = 64, we get an overflow.
Now, your task will be to solve this problem using the BigInteger class.
Look up the BigInteger class and use it to modify one of the programs above so that we can get the number of moves when n = 64. Call your new class BigIntegerTowerMoves