Explore BrainMass
Share

Explore BrainMass

    Java - Fill in Question

    This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

    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

    © BrainMass Inc. brainmass.com April 3, 2020, 10:55 pm ad1c9bdddf
    https://brainmass.com/computer-science/java/java-fill-question-470528

    Solution Summary

    The solution assists with a Java fill-in question.

    $2.19

    ADVERTISEMENT