Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Professional SQL Server 2012 Internals And Troubleshooting

Authors: Christian Bolton, Justin Langford

1st Edition

1118177657, 9781118177655

More Books

Students also viewed these Databases questions

Question

2. Identify four types of migrant groups.

Answered: 1 week ago

Question

What is the basis for Security Concerns in Cloud Computing?

Answered: 1 week ago

Question

Describe the three main Cloud Computing Environments.

Answered: 1 week ago