In this assignment, which consists of two parts, you will develop a program to administer a quiz test. The program (which is to be completed in part 2) presents the user with a menu with the following options:

  • Read the details about the questions from a text le
  • Administer the quiz; that is, present the questions and get the answers from the user
  • Display the result on the screen
  • Write the result to a text le

Quiz Questions

There are three types of quiz questions:

  • True or false questions
  • Multiple choice questions
  • Word questions

True or false questions

The interaction for a true or false question is as shown in the example below:

A checked exception must be caught or declared.
True or false?
Type true or false in lower case: true

That is, the program displays

  • A statement
  • Followed by the true or false question
  • Followed by the instruction as to how to type in the answer. The answer typed in by the user is underlined in the above display.

Multiple choice questions

The interaction for a multiple choice question is as shown in the example below:

What is the keyword used to declare a class to be a subclass of another class?
a) implements
b) extends
c) subclass
d) interface
Type a letter between a and d inclusive: b

That is, the program displays

  • The question
  • Followed by the choices
  • Followed by the instruction as to how to type in the answer. The users answer is underlined.

Word questions

For this type of question, the users answer consists of one or more words. Two examples are shown below. In the rst example, a question is asked. In the second example, a blank in a statement is to be lled in.

What is the key word for constant?
Type in your answer (use capital letters only when necessary): final
ArithmeticException is a/an _____ exception. Fill in the blank.
Type in your answer (use capital letters only when necessary): checked

That is, the program displays

  • Either a question or a statement which is followed by Fill the blank
  • Followed by the instruction as to how to type in the answer. The users answer is underlined.

Class Design

A design of the classes are shown below. The diagram includes all the attributes, but it includes only a few of the methods that will be needed. You are required to implement this design. See image.

Notes on the design:

1. Class QuizQuestion is an abstract class and its administer method is an abstract method.

2. Class QuizAnswer is an abstract class.

3. The value for attribute type is

  • T for classes TrueFalseQuestion and TrueFalseAnswer
  • M for classes MultipleChoiceQuestion and MultipleChoiceAnswer
  • W for classes WordQuestion and class WordAnswer

4. Attribute result can take value C for correct or I for incorrect.

5. The readQuestion method is a static method which reads a question from a le and returns a new question object of appropriate type. This method assumes that the cursor is at the very start of the question befre the execution of the method. And after the execution, it must leave the cursor at the beginning of the next record (if one exists). The format of the text le is described on pages 5 and 6.

6. The administer method is a method which displays the question to the user, collects the users answer and returns a new answer object of the appropriate type.

Task 1

Implement the classes in the design.

Write a test program, called QuizQuestionTester.java, to test those classes. The program should

  • Create instances of TrueFalseQuestion, WordQuestion and MultipleChoiceQuestion
  • Send messages to administer them
  • Obtain and display the coresponding QuizAnswer instances

Task 2

Write a tester program, called ReadAdministerQuestions.java, to

  • Read a number of questions from a text le (Questions.txt) and store them in list of QuizQuestion objects. (See the description of the le format given below.) To maintain collections, you can use container classes from the Java library, such as ArrayList. If you choose to use array, you can assume that we can have at most 100 questions in a quiz test, and at most 10 possible choices for a multiple choice question.
  • Display the quiz questions on the screen. Using the toString method for this task would be acceptable.
  • Administer the test (present the questions and get the answer) and store the answers in a list of QuizAnswer objects. (See the program-user interaction described below.)
  • Display the QuizAnswer objects in the list. Using the toString method for this task would be acceptable.

The format of the text le is shown in the example below.

T
try/catch blocks can be nested.
+ true
.
M
What is the keyword used to declare a class to be a subclass of another class?
- implements
+ extends
- subclass
- interface
.
W
What is the key word for constant?
+ final
.
W
ArithmeticException is a/an _____ exception. Fill in the blank.
+ unchecked
.

For the rst question,

  • The rst line indicates that it is a true or false question with letter T
  • The second line is the text of the question to be presented to the user. Another question may have a longer text but it will still occupy one line. This one-line rule applies to questions of other types as well
  • The third line indicates the correct answer; in this case the correct answer is true. The plus sign signies that this is the correct answer
  • The fourth line marks the end of the question with a dot at the beginning of the line

For the second question,

  • The rst line indicates that it is a multiple choice question with letter M
  • The second line is the text of the question to be presented to the user
  • The next few lines show the choices. The correct choice is marked with the plus sign, the incorrect ones with a minus sign. You can assume that we never have more than 10 choices
  • The next line marks the end of the question

For the third question,

  • The rst line, with letter W, indicates that this question requires one or more words as the answer
  • The second line is the text of the question to be presented to the user
  • The third line shows the correct answer, which is treated as being case-sensitive
  • The fourth line marks the end of the question

For the fourth question, the details are given similarly to the third question. But note that Fill in the blank is part of the question text on the second line.

The tester program (of Task 2) should present the questions to the user and get the answers as shown in th example below:

QUESTION 1:
A checked exception must be caught or declared.
True or false?
Type true or false in lower case: true
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
Type a letter between a and d inclusive: b
QUESTION 3:
What is the key word for constant?
Type in your answer (use capital letters only when necessary): final
QUESTION 4:
ArithmeticException is a/an exception. Fill in the blank.
Type in your answer (use capital letters only when necessary): checked
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.