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

  How pipes and tcp/ip sockets named libraries differ

What are the various kinds of clients that can be used to connect to SQL Server 2000 and the network requirements necessary for successful communications between the client and server.

  Windows live id and skydrive account

Suppose there are 1 million books within your campus library. Approximate (to the nearest order of magnitude) how several bytes of the data there are in case all these books were stored online and accessible across the computer network.

  Compute and conclude the speedup for options

Compute and conclude the speedup for options and decide the option Processor Y should take.

  What is the network

explain the main types of networks.

  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.

  Display the miles per gallon obtained for each tankful

Display the miles per gallon obtained for each tankful

  Recognize the the base case

What valid values could be passed as parameters to the function mystery.

  Project lacking the minority project

Give three examples of why a project might lack the technical feasibility.

  Algorithm to prepare a job applicant report

Develop an algorithm in order to prepare a job applicant report. Input consists of a series of records that contain the Social Security number or equivalent, last name, first name, middle initial, verbal test score, science test score, math test s..

  Implementing model to check the vulnerability

Construct a simple threat model which explains the risk this represents: attacker(s), vulnerability, assets, attack vector, and the likelihood of occurrence, likely impact, and the plausible mitigations.

  Developing the algorithm and analyzing its running time

Katt wishes you to develop an algorithm that, provided a string X, computer efficiently how many ways X can be broken up into the sequence of words.

  Write down a program that reads a person''s name

Write down a program that reads a person's name.

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