Answered step by step
Verified Expert Solution
Link Copied!

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 setText(String questionText){
text = questionText;
}
/**
* Sets the answer for this question.
*
* @param correctResponse the answer
*/
public void setAnswer(String 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 checkAnswer(String response){
return response.equals(answer);
}
/**
* Displays this question.
*/
public void display(){
System.out.println(text);
}
public class NumericQuestion extends Question
{
double answer;
// constructor
public NumericQuestion(){
super();
}
// sets the correct answer
public void setAnswer(double correctResponse){
answer = correctResponse;
}
/**
* Checks a given response for correctness.
*
* @param response the response to check
* @return true if the response was <=0.01 correctness, false otherwise
*/
@Override
public boolean checkAnswer(String response){
double givenanswer = Double.parseDouble(response);
return Math.abs(givenanswer - answer)<=0.01;
}
}
public class FillInQuestion extends Question {
// default constructor
public FillInQuestion(){
super();
}
/**
* Sets the question text.
*
* @param questionText the text of this question
*/
@Override
public void setText(String questionText){
Scanner scanner = new Scanner(questionText);
// 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.setText(question);
super.setAnswer(answer);
}
}
}
QUESTIONSAPP.JAVA
package questionsapp;
import java.util.Scanner;
import java.util.ArrayList;
public class QuestionsApp {
public static void main(String[] args){
ArrayList Questions = new ArrayList();
int totalScore =0;
NumericQuestion n1= new NumericQuestion();
n1.setText("What is the value of PI to the nearest thousandth?");
n1.setAnswer(3.141);
Questions.add(n1);
NumericQuestion n2= new NumericQuestion();
n2.setText("What is the value of the Euler's number to the nearest thousandth?");
n2.setAnswer(2.718);
Questions.add(n2);
FillInQuestion f1= new FillInQuestion();
f1.setText("The inventor of Java was _James Gosling_");
Questions.add(f1);
FillInQuestion f2= new FillInQuestion();
f2.setText("The inventor of Pascal was _Niklaus Wirth_");
Questions.add(f2);
for (Question q : Questions){
boolean isCorrect = presentQuestion(q);
if (isCorrect){
System.out.println("Correct answer :)
");
if (q instanceof NumericQuestion){
totalScore +=1;
}
if (q instanceof FillInQuestion){
totalScore +=2;
}
} else {
System.out.println("Wrong answer :(
");
}
}
System.out.printf("Total score is %d out of %d
Thank You!
", totalScore, 12);
}
/**
* Presents a question to the user and checks the response.
*
* @param q the question
*/
public static boolean presentQuestion(Question q){
q.display();
System.out.print("Your answer: ");
Scanner in = new Scanner(System.in);
String response = in.nextLine();
return q.checkAnswer(response);
}
}
THIS IS THE ERROR
error: cannot find symbol
NumericQuestion n1= new NumericQuestion();
symbol: class NumericQuestion
location: class QuestionsApp

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

Marketing Database Analytics

Authors: Andrew D. Banasiewicz

1st Edition

0415657881, 978-0415657884

More Books

Students also viewed these Databases questions

Question

Evaluating Group Performance?

Answered: 1 week ago