Add a process addtext to the question class

Assignment Help Computer Engineering
Reference no: EM1335140

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: EM1335140

Questions Cloud

Management''s particular focus : Does management have a particular focus and What I am wondering is if a resource issue occurs between two areas, does management always defer to, say, the casino over the restaurant?
Explain british airways- principles of marketing : Explain British Airways- Principles of marketing and competition and strategy and implementation and CSR
Explain the role of portfolio management : Explain the role of portfolio management in the allocation of corporate resources.
Attempt to decrease the budget deficit not increase : Would an attempt to decrease the budget deficit not increase it. Does today's deficit not create tomorrow's surplus.
Add a process addtext to the question class : Add a method addText to the Question class, and give a different implementation of ChoiceQuestion that calls addText rather than storing an array list of choices.
Can you hold the hrm vp directly accountable for the results : Can you hold the HRM VP directly accountable for the results on the measures that you have identified? Is so, how would you do that?
Show the responsibilities to the line manager : HRM with assigned responsibilities to the line manager and What are the pros and cons of each type of organizational structure
How various bit strings of length 6 : How several bit strings of length 6 is there that begin with 0 or end with a 1. How various bit strings of length 6.
Criminalistics- forensic science introduction : The defense has filed a motion to suppress the footprint evidence, handwriting analysis, and the evidence obtained using alternative light sources gathered at the crime scene at Helene Valentine's home.

Reviews

Write a Review

Computer Engineering Questions & Answers

  Modify java application that displays the product number

make a Java application that displays the product number, the name of the product, the number of units in stock, the price of each unit, and the value of the inventory (the number of units in stock multiplied by the price of each unit).

  Straight-line depreciation method calculations

Describe how to carry out the Straight-line Depreciation Method calculations and understand the meaning of elements within the Straight-line formula.

  Show your solution to place a student

Using simple loops and the logic operator "AND" and "OR," make a hierarchy chart that shows the phases, pseudo code, and flowcharts to illustrate your solution to place a student in one of the aforementioned categories.

  Create the definition of the function

Write down the definition of the function template moveNthFront that takes as a parameter a queue and a positive integer, n. The function moves the nth element of the queue to the front.

  Program that continuously outputs random numbers

Write down a code in Java that continuously outputs random numbers between 0 and 10000 until a number which is divisible by 5 is encountered.

  Write down a select statement that lists the studentid

I have tried there two queries, but I am told that I am not doing something right. Here are the criteria I used to write the queries and my current answers.

  Describe the program development cycle

Describe the importance of using a structured, modular approach when creating program requirements, design, and code.

  Determining the vulnerability in product

Specify the ethical considerations included when the security professional contacts the vendor regarding vulnerability in their product.

  Describing the microsoft access

Describe what is going on within the Microsoft Access. What role do you think SQL is playing?

  How to create an online account

A database would store the student's login name, class list, and number of registered credits. Furthermore, the database will store the administrator's login information and the classes listed in the online catalog. Add error handling to the appli..

  Algorithm for generating list of customers

Develop an algorithm in order to generate a list of customers from Glad Rags Clothing Company’s customer master file.

  What do you mean by an entity

How is it possible to get more information from the equal amount of data though using a database approach as opposed to a file approach.

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