Question: write a program called MultipleChoice.java that creates a multiple choice question with 5 possible answers. Here is my code: public class MultipleChoice{ String question =

write a program called MultipleChoice.java that creates a multiple choice question with 5 possible answers.


Here is my code:


public class MultipleChoice{

String question = (""), answerText = (""), questionText = (""),
answer_a = "", answer_b = "", answer_c = "", answer_d = "", answer_e = "";
boolean answer, option;
static char correctChar = 'f';
static int questions = 0;
static char whichAnswer;
static int index = 1;

public MultipleChoice(){

}


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


public boolean setAnswer(char whichAnswer, String answerText)
{
this.whichAnswer = whichAnswer;
this.answerText = answerText;


if (whichAnswer=='a') {
option = true;
answer_a=answerText;
}
if (whichAnswer=='b') {
option = true;
answer_b=answerText;
}
if (whichAnswer=='c') {
option = true;
answer_c=answerText;
}
if (whichAnswer=='d') {
option = true;
answer_d=answerText;
}
if (whichAnswer=='e') {
option = true;
answer_e=answerText;
}
else{
option = false;
}
return option;
}


public boolean setCorrect(char correctChar)
{
this.correctChar = correctChar;
if(correctChar == 'a' || correctChar == 'b' || correctChar == 'c' ||
correctChar == 'd' || correctChar == 'e')
answer = false;
return answer;
}


public char getCorrect()
{
return correctChar;
}


public static boolean grade(MultipleChoice q, char selection)
{
boolean compare_answers;
if(selection == correctChar)
{
compare_answers = true;
}
else
{
compare_answers = false;
}
return compare_answers;
}


public static int questionsCreated()
{
questions++;
return questions;
}


public void setIndex(int i)
{
index = i;
}


public String toString()
{
String newQuestion = index+". "+questionText+"\n "+
"a) "+answer_a+"\n "+
"b) "+answer_b+"\n "+
"c) "+answer_c+"\n "+
"d) "+answer_d+"\n "+
"e) "+answer_e+"\n ";

return newQuestion;
}
}



Then I had to create another program called Quiz.java that contains 5 MultipleChoice questions and the name of the quiz.


The part that I am stuck on is the method:


public boolean addQuestion(int index, MultipleChoice q)


It says that this method should add a question to the quiz and specify the index of the question (1-5). If an invalid number is sent (one that is not 1-5), then the method should return false and not add the question.

BUT I DONT EVEN KNOW WHERE TO START ON THIS METHOD!!!


I should be able to type this in the interactions pane:


q.setAnswer('a', "First Choice");

q.setAnswer('b', "Second Choice");

q.setAnswer('c', "Third Choice");

q.setAnswer('d', "Fourth Choice");

q.setAnswer('e', "Fifth Choice");

q.setQuestion("This is the question.");

example.addQuestion(3, q)



Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!