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

  Preventing the pci specifications

To prevent having the whole network subject to the PCI specifications, how would you segment the network in order to decrease the scope of compliance?

  How to identify areas for improvement

plan a form that you would disseminate to your end user community that will aid in the assessment of a current system to identify areas for improvement.

  Application to computer science

Find the matrices that represent the relations.

  Listing the key points of the policies & procedures.

Find out some significant policies and procedures that system administrators use to set up desktop workstations

  The ajax extensions tab of the toolbox

Inside the ContentTemplate element of the UpdatePanel server control add the standard RadioButtonList server control, Label server control and Button server control.

  Write down a c function that adds the values

Write a C function that adds the values of all elements in a two-dimensional array that is passed to the function, suppose that the array is an array of double-precision numbers having 4 rows and 5 columns.

  Write c program prompt the user for a filename to open

write C program prompt the user for a filename to open

  How it would increase or lower the protocol processing load

This solution explores and defines the requirement for routers to support both IPv4 and IPv6 protocol stacks and explains the various types of connections a dual stack router can support, and why such connections are necessary.

  Use the techniques to do some black-box testing

how to Download a shareware version of some commercial software.

  Why is an object (oop) a module

Why is an object (OOP) a module

  Make a clear button that will clear both text boxes

Your employer has requested the growth of a software application to calculate the area of a circle. The application must accept only one value (i.e., the radius), and it must display the result in decimal value.

  Who is developing software for a wireless system

In what way can a virtual hardware platform help a programmer who is developing software for a wireless system? What do you see as a potential problem of developing for a virtual hardware platform.

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