I'm making a quiz program. First step, I'm taking the quiz questions and their correct answers from the teacher/ user. I have a child class named TrueFalseQuestion which takes the boolean model answer and the string question as a parameter. I've made an array of TrueFalseQuestion type and I'm stuck at this part where I run the code, insert a question and no matter whether the model answer I've inserted is true or false, it's always stored as false when I print it out. HELP? Here's this part of my code:
System.out.println("How many true or false questions would you like to include in your quiz?");
int l=s.nextInt();
TrueFalseQuestion[] qu2= new TrueFalseQuestion[l];
int x;
for(x=0;x<l;x++){
System.out.println("Please insert question "+(x+1)+":\n");
String Q2=s.next();
System.out.println("Please insert the correct answer");
boolean A2=s.nextBoolean();
qu2[x]=new TrueFalseQuestion(Q2,A2);
System.out.println(qu2[x].GetCorrectAnswer());
}
EDIT: Here's the TrueFalseQuestion code
public class TrueFalseQuestion extends Question {
private boolean CorrectB;
public TrueFalseQuestion(String qu, boolean b){
super(qu);
}
@Override
public void GetQuestion() {
System.out.println(getMyText()+"\n Is this statement true or false?");
}
@Override public String GetAnswer() {
System.out.println("Insert Answer: ");
boolean MyAnswer=s.nextBoolean();
return Boolean.toString(MyAnswer);
}
@Override public String CheckAnswer() {
return Boolean.toString(GetAnswer().equalsIgnoreCase(Boolean.toString(GetCorrectAnswer())));
}
/** * return the MyAnswer / /* * return the CorrectAnswer / public boolean GetCorrectAnswer() { return CorrectB; } /* * return the MyAnswer */
}