java - Always Getting a "FALSE" -



java - Always Getting a "FALSE" -

i'm making quiz program. first step, i'm taking quiz questions , right answers teacher/ user. have kid class named truefalsequestion takes boolean model reply , string question parameter. i've made array of truefalsequestion type , i'm stuck @ part run code, insert question , no matter whether model reply i've inserted true or false, it's stored false when print out. help? here's part of code:

system.out.println("how many true or false questions include in 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 right answer"); boolean a2=s.nextboolean(); qu2[x]=new truefalsequestion(q2,a2); system.out.println(qu2[x].getcorrectanswer()); }

edit: here's 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 statement true or false?"); } @override public string getanswer() { system.out.println("insert answer: "); boolean myanswer=s.nextboolean(); homecoming boolean.tostring(myanswer); } @override public string checkanswer() { homecoming boolean.tostring(getanswer().equalsignorecase(boolean.tostring(getcorrectanswer(‌​)))); } /** * homecoming myanswer / /* * homecoming correctanswer / public boolean getcorrectanswer() { homecoming correctb; } /* * homecoming myanswer */ }

your problem constructor:

public truefalsequestion(string qu, boolean b){ super(qu); }

you don't set field correctb defaults default value in java false

the prepare is

public truefalsequestion(string qu, boolean b){ super(qu); correctb = b; }

java oop

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -