Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a class to manage a simple test question. This class (a) inherits class T

ID: 3734517 • Letter: C

Question

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.

public class TrueFalseQuestion ( protected String questionText- null; private boolean answe r = false; public TrueFalseQuestion) ( this.questionText = "No Question"; public void setQuestionText(String questionText) f this.questionText questionText; public String getQuestion) I return questionText + "(true/false)" public final void setAnswer (boolean answer) this.answe r = answer; public final boolean checkAnswer (boolean attempt) t return answerattempt

Explanation / Answer


public class TrueFalseQuestion {

   protected String questionText = null;
   private boolean answer = false;

   public TrueFalseQuestion() {
       this.questionText = "No Question";
   }

   public String getQuestion() {
       return questionText + "(true / false)";
   }

   public void setQuestionText(String questionText) {
       this.questionText = questionText;
   }

   public boolean checkAnswer(boolean attempt) {
       return answer == attempt;
   }

   public void setAnswer(boolean answer) {
       this.answer = answer;
   }

}


public class TestQuestion extends TrueFalseQuestion {

   private String answer;

   public TestQuestion() {
       super();
   }

   public TestQuestion(String question, String answer) {
       super.setQuestionText(question);
       this.answer = answer;
   }

   // method overridden
   @Override
   public String getQuestion() {

       return super.questionText;
   }

   // method overloaded
   public void setAnswer(String answer) {
       this.answer = answer;
   }

   public String getAnswer() {
       return answer;
   }

   // method overloaded
   public boolean checkAnswer(String attempt) {
       return this.getAnswer().contains(attempt);
   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote