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

  Generate an object-oriented design for a system

Generate an object-oriented design for a system that keeps tracks of your CD and DVD collection. Identify each of the classes, associated data, and operations for the classes.

  What graphical element appears on a shortcut icon

Which of the following locations is not a valid place from which to delete a file and send it to the Recycle Bin?

  Design application to declare an array

Design an application that declares an array of 10 HousePlants. Prompt the user user for data for each of the HousePlants, then display all the values.

  Prepare a computer program to simulate the traffic

Write a computer program to simulate the traffic on a 2D plane under different traffic light control schemes.

  Write program to compute diameter in centimeters

Write a program to compute the diameter in centimeters of a steel rod, an aluminum rod, and a copper rod, which can withstand a particular compression load.

  Determine seperate total of positive and negative numbers

Read set of 40 positive and negative numbers entered from keyboard and determine seperate total of positive and negative numbers. How to show modular design of above statement

  Javascript program that allows a user to input three integer

Write a JavaScript program that allows a user to input three integers using text boxes in a form. (Hint: You need to use the built-in parseInt function to convert the input strings to integers.)

  Discuss the purpose of the php procedures

Discuss the purpose of the PHP procedures that you have written.

  Console application that displays the sizes of the two files

Create a file that contains your favorite movie quote. Use a text editor such as Notepad and save the file as Quote.txt. Copy the file contents and paste them into a word-processing program such as Word. Save the file as Quote.doc.

  Explain the use of the of sql keyword select

Explain the use of the GROUP BY keyword. Include an example based on the CUSTOMER table from the General Sales database.

  Recursive method to read in string of characters

Trying to write a recursive method that reads in a string of characters and checks to see if the first character is either a 'D' or and 'E', then is followed by a string of one or more 'F's.

  Describe the contents of text box after button is clicked

Describe the contents of the text box after the button is clicked

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