Question: I need help completing this assignemnt can you provide comments and provide everything that is needed i dont know why its uploading the code in

I need help completing this assignemnt can you provide comments and provide everything that is needed i dont know why its uploading the code in a table but here is everything.

Complete 9.1 and 9.3 based on class Question there are 4 classes to upload.

P9.1 Add a class NumericQuestion to the question hierarchy of Section 9.1. If the response and the expected answer differ by no more than 0.01, then accept the response as correct.

P9.3 Modify the checkAnswer method of the Question class so that it does not take into account different spaces or upper/lowercase characters. For example, the response "JAMES gosling" should match an answer of "James Gosling".

Section 9.1

section_1/Question.java
1
/**
2
 A question with a text and an answer.
3
*/
4
public class Question
5
{
6
 private String text;
7
 private String answer;
8
9
 /**
10
 Constructs a question with empty question and answer.
11
 */
12
 public Question()
13
 {
14
 text = "";
15
 answer = "";
16
 }
17
18
 /**
19
 Sets the question text.
20
 @param questionText the text of this question
21
 */
22
 public void setText(String questionText)
23
 {
24
 text = questionText;
25
 }
26
27
 /**
28
 Sets the answer for this question.
29
 @param correctResponse the answer
30
 */
31
 public void setAnswer(String correctResponse)
32
 {
33
 answer = correctResponse;
34
 }
35
36
 /**
37
 Checks a given response for correctness.
38
 @param response the response to check
39
 @return true if the response was correct, false otherwise
40
 */
41
 public boolean checkAnswer(String response)
42
 {
43
 return response.equals(answer);
44
 }
45
46
 /**
47
 Displays this question.
48
 */
49
 public void display()
50
 {
51
 System.out.println(text);
52
 }
53
}

This question class is very basic. It does not handle multiple-choice questions, numeric questions, and so on. In the following sections, you will see how to form subclasses of the Question class.

Here is a simple test program for the Question class:

section_1/QuestionDemo1.java
1
import java.util.Scanner;
2
3
/**
4
 This program shows a simple quiz with one question.
5
*/
6
public class QuestionDemo1
7
{
8
 public static void main(String[] args)
9
 {
10
 Scanner in = new Scanner(System.in);
11
12
 Question q = new Question();
13
 q.setText("Who was the inventor of Java?");
14
 q.setAnswer("James Gosling");
15
16
 q.display();
17
 System.out.print("Your answer: ");
18
 String response = in.nextLine();
19
 System.out.println(q.checkAnswer(response));
20
 }
21
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!