Explore BrainMass

Java - Fill in Question

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
The first U.S. president was _____
Your answer:
George Washington

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(;
for (Question q : quiz)
System.out.println("Your answer: ");
String response = in.nextLine();

You need to supply the following class in your solution:


Solution Summary

The solution assists with a Java fill-in question.