Click here to Skip to main content
14,970,229 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Write a program to create a simple quiz application as shown below
• The Question class is a new class with the following features:
o It is an abstract class;
o It includes a constructor method that receives a String and stores it in the private variable myText;

o It includes a public accessor method getText() for myText;
o It includes abstract method specifications for getQuestion(), getAnswer() and checkAnswer()

The ShortAnswerQuestion class is a derived class
o It now extends the Question class;
o Write a constructor method ;
o Its three concrete method definitions which overrides the abstract methods

The FillInBlankQuestion class is just like the ShortAnswerQuestion class with the following modifications:

o Its getQuestion() method must append the string "\nFill in the blank." to the end of the question text. Note: The question text itself does not change! Use the getText() accessor to get the main text of the question, and then use string concatenation to add "\nFill in the blank." ;

The TrueFalseQuestion class is just like the ShortAnswerQuestion class with the following modifications:

o Its myAnswer data attribute is a boolean and the explicit-value constructor receives a boolean value for the answer;
o Its getQuestion() method must append the string "\nIs this statement true or false?" to the end of the question text;
o Its getAnswer() method must still return a string (to match the abstract method it is overriding), so it needs to cast the boolean answer into a string (i.e., into "true" or "false") - you can do this using new Boolean(myAnswer).toString();
o Its checkAnswer() method must compare the string received from the calling program (answer) against a string version of the correct answer - you can do this using getAnswer().equalsIgnoreCase(answer)).

The getQuestion() accessor method calls the parent method getText() in order to gain access to the text instance variable.

Create a class called Simplequiz to store a list of Question objects. Make use of polymorphism concept.
Posted
v2
Comments
joshrduncan2012 25-Nov-13 9:17am
   
It doesn't work like that here. What questions do you have? What have you done so far? Where are you stuck?
phil.o 25-Nov-13 11:27am
   
Are you seriously expecting us to do your homework?
Reported as abusive; what you are trying to do is basically cheating.

Homework is for your benefit not ours.

Try and do what you know and ask questions on what you don't know.
   
Please don't ask us to do your own homework. That would defeat the very purpose of it.
So, try yourself and ask here specific questions when you get stuck.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900