Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

package pa5; public class TrueFalseQuestion { protected String questionText = null; private boolean answer = false; public TrueFalseQuestion() { this.questionText = No Question; } public

package pa5;

public class TrueFalseQuestion { protected String questionText = null; private boolean answer = false; public TrueFalseQuestion() { this.questionText = "No Question"; } public void setQuestionText(String questionText) { this.questionText = questionText; } public String getQuestion() { return questionText + " (true/false)"; }

public final void setAnswer(boolean answer) { this.answer = answer; } public final boolean checkAnswer(boolean attempt) { return answer == attempt; } }

package pa5;

public class Pa5 {

public static void main(String[] args) { } }

1. Download pa5.zip, extract the NetBeans project folder Pa5 from it, then open it in NetBeans. 2. Examine the class TrueFalseQuestion. Note that it (a) has a protected String field questionText and a private boolean answer. (b) has a constructor that assigns an initial value to the field questionText. (c) contains four methods, one to set the question text, one to return a string containing the question with instructions, a final method to set the answer and a final method to check an answer against the set answer. 3. Create code in class Pa5 to demonstrate the use of an object of type TrueFalseQuestion class as a data type. (See the example run for ideas.) 4. Create a class to manage a simple test question. This class (a) inherits class TrueFalseQuestion . (b) must contain a constructor or constructors that use super to call the constructor of class TrueFalseQuestion. (c) must use overriding polymorphism to override the inherited method getQuestion so that the string returned is appropriate for a question needing a string answer instead of a boolean answer. (d) must use overloading polymorphism to create appropriate versions of methods setAnswer and checkAnswer. (e) may contain any other methods or fields (data members) needed. 5. Create code in class Pa5 to demonstrate that your simple test question class is an effective data type. (See the example run for ideas.) CMPS 260 Spring 2018 Programming Assignment #5 2 6. Create a class to manage a multiple choice type question. This class (a) inherits class TrueFalseQuestion (b) must contain a default constructor that uses super to call the constructor of class TrueFalseQuestion and sets the number of answer choices to a fixed number greater than 1. (c) must contain a parametrized constructor that uses super to call the constructor of class TrueFalseQuestion and sets the number of answer choices to that of a passed parameter, but only if the value of the parameter is greater than 1. (d) must use overriding polymorphism to override the inherited method getQuestion so that the string returned is appropriate for a question needing a string answer instead of a boolean answer. (e) must use overloading polymorphism to create appropriate versions of methods setAnswer and checkAnswer. (f) may contain any other methods or fields (data members) needed. Suggested methods include a method for adding a choice to the list of multiple guess choices, returning the maximum number of multiple guess choices and returning the current number of multiple guess choices. 7. Create code in class Pa5 to demonstrate that your multiple choice test question class is an effective data type. (See the example run for ideas.) Requirements No changes are allowed to class TrueFalseQuestion. All programmer created classes must be in separate files, i. e. each programmer created class must be the only class in its file. All user I/O is to occur in class Pa5. User I/O is not allowed in the classes that inherit class TrueFalseQuestion. I. e. there can be no code that accepts input from the user and or sends output to the user in TrueFalseQuestion, simple question or the multiple choice question classes. Tips Write and test the code to demonstrate the use of a TrueFalseQuestion object in Pa5 first. Of the two classes to be created, write the simple question class first and test it by writing the simple class solution code. Then tackle the choice question class. Adding to a string results in a chance of line when that string is output. CMPS 260 Spring 2018 Programming Assignment #5 3 Example run: (user input in red) Demonstration of making questions: Enter a true/false question: "terra firma" means "dry land" Enter the answer to the true/false question (true or false): true Enter a simple question: Which is heavier, gold or silver? Enter the answer to the simple question: gold Enter the number of choices (> 1): 3 Enter a choice question: What is the longest river on earth? Enter choice 1: Mississippi Enter choice 2: Nile Enter choice 3: Amazon Enter the answer to the choice question: Nile Demonstration of asking questions: "terra firma" means "dry land" (true/false) false Incorrect. Try again. "terra firma" means "dry land" (true/false) true Correct Question: Which is heavier, gold or silver? Enter your answer: silver Incorrect. Try again. Question: Which is heavier, gold or silver? Enter your answer: gold Correct Question: What is the longest river on earth? Mississippi Nile Amazon Amazon Incorrect. Try again. Question: What is the longest river on earth? Mississippi Nile Amazon Nile Correct CMPS 260 Spring 2018 Programming Assignment #5 4 Additional Requirements (a) Identifiers must be descriptive, i. e. must self document. The only exception granted is in the case of a for variable, that is a variable created as a simple counter as in the control variable in a for loop statement.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Refactoring Databases Evolutionary Database Design

Authors: Scott Ambler, Pramod Sadalage

1st Edition

0321774515, 978-0321774514

More Books

Students also viewed these Databases questions

Question

What is meant by 'Wealth Maximization ' ?

Answered: 1 week ago