Problem Description

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 file
  • 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 file

Quiz Questions

There are three types of quiz questions:

  • True or false questions
  • Word questions
  • Multiple choice 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.

Word questions

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

What is the key word to define constants?
Type in your answer: final
ArithmeticException is a/an _____ exception. Fill in the blank.
Type in your answer: checked

As illustrated, 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.

An answer may be case-sensitive or not. The answer to the first question in the example above is case-sensitive. Thus, the answer Final, for example, will marked as being incorrect. Whereas, for the second question, the answer UNchecked, for example, will be marked as correct.

Multiple choice questions

The interaction for a multiple choice question is as shown in the examples 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 in a string of letters from a to d (in alphabetical order): b
Which of the following are keywords to specify access level?
choices:
a) public
b) protected
c) package
d) private
e) local
Type in a string of letters from a to e (in alphabetical order): abd

As illustrated, 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.

Note carefully that there may be more than one correct choice for a question (as for the second question above).

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:

  • Class QuizQuestion is an abstract class and its administer method is an abstract method.
  • Class QuizAnswer is an abstract class.
  • Attribute result can take value C for correct or I for incorrect.
  • The readQuestion method is a static method which reads a question from a file and returns a new question object of appropriate type. See the requirements for this method in Task 2.
  • 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, WordQuestionandMultipleChoiceQuestion
  • Send messages to administer them
  • Obtain and display the corresponding QuizAnswer instances

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.

Task 2

Write a tester program, called ReadAdministerQuestions.java, to

Read a number of questions from a text file (Questions.txt) and store them in list of QuizQuestion objects. (See the description of the file format given below.)

This method assumes that

  • Before the execution of the method, the cursor is at the beginning of the line after the question type (T, W or M).
  • And after the execution, it must leave the cursor at the beginning of the next record (if one exists), i.e. the line following the line with the dot.

In other words, thinking of the text file as consisting of several records, each of which spec- ifies a question, with the dot as the termination of the record, we can state the requirements above as follows;

  • Before the execution of the method, the cursor must be at the beginning of the second line of next the record, and
  • After the execution, the cursor must be at the beginning of the first line of the next record

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 file is shown in the example below.

T
try/catch blocks can be nested.
+ true
.
W
ArithmeticException is a/an _____ exception. Fill in the blank.
+ unchecked
.
W
What is the key word to define constants?
+ final//CS
.
M
What is the keyword used to declare a class to be a subclass of another class?
- implements
+ extends
- subclass
- interface
.
M
Which of the following are keywords to specify access level?
+ public
+ protected
- package
+ private
- local
.

For the first question,

  • The first 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 signifies 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 first 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 Note that Fill in the blank is part of the question text.
  • The third line shows the correct answer (which is not case-sensitive, compare this with the third question)
  • The fourth line marks the end of the question

The third question is similar to the second one, but the correct answer is given by the line

+ final//CS

in which the tag //CS is used to indicate that the answer (which is final) is case-sensitive.

For the fourth question,

  • The first 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

The fifth question is similar to the fourth one, but it has several correct choices, as indicated by several plus signs. The correct answer for this question is required to be abd, not adb for example.

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

QUESTION 1
try/catch blocks can be nested.
Type true or false: true
QUESTION 2
ArithmeticException is an _____ exception. Fill in the blank.
Type your answer: unchecked
QUESTION 3
What is the key word to define constants?
Type your answer: final
QUESTION 4
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 in a string of letters from a to d (in alphabetical order): b
QUESTION 5
Which of the following are keywords to specify access level?
a) public
b) protected
c) package
d) private
e) local
Type in a string of letters from a to e (in alphabetical order): abd
// followed by the display of the QuizAnswer objects
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.