Answered step by step
Verified Expert Solution
Question
1 Approved Answer
NEED HELP WITH JAVA ERROR QUESTIOIN.JAVA package questionsapp; import java.util.Scanner; / * * * A question with a text and an answer. * / public
NEED HELP WITH JAVA ERROR
QUESTIOIN.JAVA
package questionsapp;
import java.util.Scanner;
A question with a text and an answer.
public class Question
private String text;
private String answer;
Constructs a question with empty question and answer.
public Question
text ;
answer ;
Sets the question text.
@param questionText the text of this question
public void setTextString questionText
text questionText;
Sets the answer for this question.
@param correctResponse the answer
public void setAnswerString correctResponse
answer correctResponse;
Checks a given response for correctness.
@param response the response to check
@return true if the response was correct, false otherwise
public boolean checkAnswerString response
return response.equalsanswer;
Displays this question.
public void display
System.out.printlntext;
public class NumericQuestion extends Question
double answer;
constructor
public NumericQuestion
super;
sets the correct answer
public void setAnswerdouble correctResponse
answer correctResponse;
Checks a given response for correctness.
@param response the response to check
@return true if the response was correctness, false otherwise
@Override
public boolean checkAnswerString response
double givenanswer Double.parseDoubleresponse;
return Math.absgivenanswer answer;
public class FillInQuestion extends Question
default constructor
public FillInQuestion
super;
Sets the question text.
@param questionText the text of this question
@Override
public void setTextString questionText
Scanner scanner new ScannerquestionText;
spliting the string using the delimiter
scanner.useDelimiter;
taking first part into question
String question scanner.next;
taking another part to answer
String answer scanner.next;
appending delimiter to the question
question ;
closing the scanner object
scanner.close;
setting the question and answer of the question class
super.setTextquestion;
super.setAnsweranswer;
QUESTIONSAPP.JAVA
package questionsapp;
import java.util.Scanner;
import java.util.ArrayList;
public class QuestionsApp
public static void mainString args
ArrayList Questions new ArrayList;
int totalScore ;
NumericQuestion n new NumericQuestion;
nsetTextWhat is the value of PI to the nearest thousandth?";
nsetAnswer;
Questions.addn;
NumericQuestion n new NumericQuestion;
nsetTextWhat is the value of the Euler's number to the nearest thousandth?";
nsetAnswer;
Questions.addn;
FillInQuestion f new FillInQuestion;
fsetTextThe inventor of Java was James Gosling;
Questions.addf;
FillInQuestion f new FillInQuestion;
fsetTextThe inventor of Pascal was Niklaus Wirth;
Questions.addf;
for Question q : Questions
boolean isCorrect presentQuestionq;
if isCorrect
System.out.printlnCorrect answer :
;
if q instanceof NumericQuestion
totalScore ;
if q instanceof FillInQuestion
totalScore ;
else
System.out.printlnWrong answer :
;
System.out.printfTotal score is d out of d
Thank You!
totalScore, ;
Presents a question to the user and checks the response.
@param q the question
public static boolean presentQuestionQuestion q
qdisplay;
System.out.printYour answer: ;
Scanner in new ScannerSystemin;
String response innextLine;
return qcheckAnswerresponse;
THIS IS THE ERROR
error: cannot find symbol
NumericQuestion n new NumericQuestion;
symbol: class NumericQuestion
location: class QuestionsApp
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started