Java Assignment 1 – Quiz Taking Program

Objectives:

After completing this assignment, the student should be able to:

1. Draw a class diagram.

2. Design test cases scenarios.

3. Design junit test cases.

4. Read data from a file.

5. Write data to a file.

6. Add to, find and traverse an arrayList.

7. Use inheritance and override methods.

8. Create abstract classes.

 

Problem Specifications:

Develop a program to generate and take a quiz.  The program takes quiz questions from a file named quizQuestions.txt, generates the quiz for the user to take and then checks the answers.  The quiz score is then written to a file named quizScores.txt.  You MUST use inheritance (3 levels) and an abstract class in your design.  

The quiz consists of different kinds of questions:

a) Fill-in-the-blank

b) Single choice

c) Multiple choice

d) Numeric 

 

For a fill-in-the-blank question, the question is provided with the answer surrounded by *. The program should be case insensitive, and accept the answer whether it is lowercase or uppercase.  

For a numeric question, if the user response and the answer differ by no more than plus or minus 0.01 then the answer is correct.

The single choice and multiple choice questions can have any number of choices.  (For example, one question may have 3 choices, another one may have 7 choices).  Single choice questions have 1 correct answer.  Multiple choice questions can have multiple correct answers.

An example quizQuestions.txt file is shown below.  Each line in the file starts with the question type. The question type field has the following values:

- F for fill-in-the-blank

- S for single choice

- M for multiple choice

- N for numeric

If the question type field is S or M, then the question text field contains the number of choices for that question, followed by a list of the choices, separated by commas. (see sample file)

A question can display its text and it can check whether a given response is the correct answer.

 

Each time the quiz program is run, it should prompt the user to enter his or her name.  At the end of the quiz, the program must inform the user of their score on the quiz, as a raw value and a percentage.  It must also write the user name and quiz score (in percentage) to the file named quizScores.txt.  It should append the results to the end of the file.  A sample run of the program is included below.

 

 

Your design must include the following:

a) Your program must store the quiz questions read in from the quizQuestions.txt file in an arrayList.

b) Your program must store the choices for each choice question in an arrayList.

c) Inheritance must be used.  The root of the hierarchy must be a Question class, which is abstract. (Hint: there should be 3 levels of inheritance)

d) The Question class must handle displaying the question to the QuizRunner class.

e) The Question class must handle checking whether an answer is correct. 

f) A QuizRunner class must handle all input and output with the user.  If you have any print’s or read’s in any other class of your program, then something is wrong.

 

 

To Do:

1) Draw a class diagram for the program using Visual Paradigm.  Make sure that all classes listed in the problem specification are included.  

2) Generate a list of test case scenarios to fully test the program. Each test case should describe the scenario, the input, and the expected result.  Save this in a Word document.

3) Code the JUnit tests, based on your test case scenarios.  You must have JUnit test cases to test the Questions class and all of its subclasses.  You do not need to write JUnit test cases to test the QuizRunner class.  That is better done manually.  Remember to have a separate JUnit class for each class that you are testing.

4) Code the program and fully test the program for all error conditions described in the specification.  You must use ArrayList, inheritance and abstract classes where specified in this assignment to obtain a passing grade.

Need a custom answer at your budget?

This assignment has been answered 4 times in private sessions.

Or buy a ready solution below.

Buy ready solution

Solution previews

© 2024 Codify Tutor. All rights reserved