question archive Add a class FillInQuestion to the question hierarchy of How To 10
Subject:Computer SciencePrice: Bought3
Add a class FillInQuestion to the question hierarchy of How To 10.1. An object of this class is constructed with a string that contains the answer, surrounded by _ _, for example, "The inventor of Java was _James Gosling_". The question should be displayed as
The inventor of Java was _____
Here is a sample program run:
_____ was the inventor of Java.
Your answer:
James Gosling
true
The first U.S. president was _____
Your answer:
George Washington
true
Use the following class as your main class:
import java.util.Scanner;
public class QuestionDemo
{
public static void main(String[] args)
{
Question[] quiz = new Question[2];
FillInQuestion question0 = new FillInQuestion(
"_James Gosling_ was the inventor of Java.");
quiz[0] = question0;
FillInQuestion question1 = new FillInQuestion(
"The first U.S. president was _George Washington_");
quiz[1] = question1;
Scanner in = new Scanner(System.in);
for (Question q : quiz)
{
q.display();
System.out.println("Your answer: ");
String response = in.nextLine();
System.out.println(q.checkAnswer(response));
}
}
}
You need to supply the following class in your solution:
FillInQuestion