Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part I: [10 Marks] Modify the Question class In this lab you are going to implement the inheritance hierarchy shown below. Youve already done QuizMaker

Part I: [10 Marks] Modify the Question class

In this lab you are going to implement the inheritance hierarchy shown below. Youve already done QuizMaker and Question.

image text in transcribed

Modify your Question class to have a String displayQuestion() method which returns a string containing the question and difficulty of the question. Modify QuizManager to use this displayQuestion method when displaying a question to the user in giveQuiz. Only modify the previous files when directed to do so, unless there are errors to fix

Part II: [15 marks] The FillInQuestion subclass

Create a class called FillInQuestion that extends Question. This kind of question is created using a single string that contains the answer, surrounded by _- -_. A sample question like this would be The color _-white-_ is the most common color found on flags. The question should be displayed to the user as The color _____ is the most common color found on flags.

The first line of the constructor must be a call to Questions constructor using super. But you need to process the String before calling super. Do the following

Write two private static methods String parseQ(String) and String parseA(String) These take the constructors parameter and return the computed question/answer as specified above o So parseQ(The sky is _-blue-_) might return The sky is _________ o The __________ should be reasonably long.

Now your constructor might look like public FillInQuestion(String sentence, Diffenum diff) { super(parseQ(sentence), parseA(sentence), diff) on the first line.

If FillInQuestions parameter String does not contain _- and -_ and not in the correct order, throw an IllegalArgumentException. (You can throw this in the parseQ method)

Override Questions copy method. It still must return Question, but it will be creating a FillInQuestion object so that the actual type of the copy is correct.

Modify QuizManager to include at least two FillInQuestions in a quiz.

Write a JUnit test class that tests the constructor and copy methods of the FillInQuestion class are working properly. (The other methods are already tested by the JUnit test class for Question)

Part III: [15 marks] The NumericQuestion subclass

Create a class called NumericQuestion that extends Question. The constructor has two double parameters for the answer, the first is the correct answer, the second is the tolerance as shown in the example below. If an attempted answer is within the tolerance value of the correct answer, it is considered correct. Override the checkAnswer method to properly check an attempted answer.

NumericQuestion(What is the value of PI?, 3.14, 0.01, Question.Difficulty.Easy) would allow any value between 3.13 and 3.15 as correct. You can assume the attempted answer given to checkAnswer will convert to a double without throwing an exception

Override Questions copy method. It still must return Question, but it will be creating a NumericQuestion object so that the actual type of the copy is correct.

Modify QuizManager to include at least two NumericQuestions in a quiz.

Write a JUnit test class that tests the constructor, copy method, and new version of checkAnswer of the NumericQuestion class are working properly.

done QuizMaker and

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MFDBS 91 3rd Symposium On Mathematical Fundamentals Of Database And Knowledge Base Systems Rostock Germany May 6 9 1991

Authors: Bernhard Thalheim ,Janos Demetrovics ,Hans-Detlef Gerhardt

1991st Edition

3540540091, 978-3540540090

More Books

Students also viewed these Databases questions