In which country was the inventor of java born

Assignment Help Programming Languages
Reference no: EM13950475

Add a method addText to the Question class, and provide a different implementation of ChoiceQuestion that calls addText rather than storing an array list of choices.

Here is a sample program run:

Who was the inventor of Java?
Your answer:
James Gosling
true
In which country was the inventor of Java born?
1: Australia
2: Canada
3: Denmark
4: United States
Your answer:
2
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];

quiz[0] = new Question("Who was the inventor of Java?");
quiz[0].setAnswer("James Gosling");

ChoiceQuestion question = new ChoiceQuestion(
"In which country was the inventor of Java born?");
question.addChoice("Australia", false);
question.addChoice("Canada", true);
question.addChoice("Denmark", false);
question.addChoice("United States", false);
quiz[1] = question;

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));
}
}
}

Complete the following classes in your solution:

/**
A question with multiple choices.
*/
public class ChoiceQuestion extends Question
{
// Add any needed instance variables, but don't store the choices
// The choices should be added to the text of the superclass

/**
Constructs a choice question with a given text and no choices.
@param questionText the text of this question
*/
public ChoiceQuestion(String questionText)
{
...
}

/**
Adds an answer choice to this question.
@param choice the choice to add
@param correct true if this is the correct choice, false otherwise
*/
public void addChoice(String choice, boolean correct)
{
...
}
}

/**
A question with a text and an answer.
*/
public class Question
{
private String text;
private String answer;

/**
Constructs a question with a given text and an empty answer.
@param questionText the text of this question
*/
public Question(String questionText)
{
text = questionText;
answer = "";
}

/**
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);
}

/**
Add a line of text to the question text.
*/
public void addLine(String line)
{
...
}

/**
Displays this question.
*/
public void display()
{
System.out.println(text);
}
}

Reference no: EM13950475

Questions Cloud

Existing product and identify its target market : Select an existing product and identify its target market. Describe how each variable of the marketing mix (product, price, place, and promotion) is being executed. Address at least three elements of each variable.Focus of The Marketing Mix
Determine the exergetic efficiency : For the turbine-compressor arrangement of Problem 6.164, determine the exergetic efficiency for (a) the turbine, (b) the compressor, (c) an overall control volume enclosing the turbine and compressor. Let T0 5 300 K.
What are the time and space requirements for computing t(n) : The following recurrence equation gives the expected number of comparisons for Quicksort, given that the "pivot element" is selected uniformly at random from the list:
Effects of motion and gravity : A pump operating at steady state takes in saturated liquid water at 65 lbf/in.2 at a rate of 10 lb/s and discharges water at 1000 lbf/in.2 The isentropic pump efficiency is 80.22%. Heat transfer with the surroundings and the effects of motion and ..
In which country was the inventor of java born : Add a method addText to the Question class, and provide a different implementation of ChoiceQuestion that calls addText rather than storing an array list of choices.
Description of the actions you would take in this situation : Description of the actions you would take in this situation, and why. Justify these actions by referencing appropriate laws, ethical standards, and professional guidelines
Discuss sharing economy from a supply and demand standpoint : Discuss the sharing economy from a supply and demand standpoint. How do companies like Uber and Airbnb affect supply and demand in the markets for shared rides (taxis, limos, etc.) and rented rooms, respectively?
Domestic water heating with conventional electrical : Tankless microwave water heating systems have been introduced that not only quickly provide hot water but also significantly reduce the exergy destruction inherent in domestic water heating with conventional electrical and gas- fueled water heater..
How many bit strings of length 8 are palindromes : How many bit strings of length 6 is there that begin with 0 or end with a 1?

Reviews

Write a Review

Programming Languages Questions & Answers

  Using datagrid in an application

Update the field named fldQuestionDescription.

  Create a file values.txt contains the data

Make sure your program is clear with no syntactical errors, correctly uses i/o syntax, correctly uses branching and looping syntax, that it contains functions with correct parameters and return values, that it correctly uses arrays, and that you p..

  Scripting language programming in perl

course Scripting Language Programming,  Assignment   -  Perl,  ? Your coding style should conform to general Perl coding conventions. Your scripts should be clean, neat, and well-formatted (e.g. indention). Identifiers should also be properly name..

  Develop a form using jsp that collects client body statistic

Develop a form using JavaScript that collects client body statistics and customer contact information for record keeping and marketing purposes.

  Two-level memory cache hierarchy

Explain how you would pipeline the four following pairs of statements.

  A method to calculate the value of the entire inventory

Create a method to calculate the value of the entire inventory. Create another method to sort the array items by the name of the product.

  Write a class representing a line item in a shopping cart

Test the program and provide a list of comprehensive test cases used to validate the application and include these test cases in a word document containing all UML diagrams and descriptions.

  View the process of making changes as recursive

You can view the process of making changes as recursive. You first see if any dollars are required, subtract them from the total, and then make change for what remains.

  Create the logic for the application fast-food resturant

Create the logic for the application which permits a user to enter the ordered item continuosly until sentinel value is entered.

  Determine the hidden cost if a recursive algorithm is

question 1 explain which one you should choose memoized-cut-rod or cut-rod. defend your decision by explaining the

  Define object-oriented programs

We are working on Object-Oriented Programs and I am lost.

  Application for calculation

Which school had the most kids playing basketball

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd