android - Shuffle Class Instances -
my program quiz asks questions states create 3 instances of class state
state st1 = new state(); state st2 = new state(); state st3 = new state();
like asks question state capital of st1.name , line below gives 3 option
string builder sb; sb.append("what capital of "+st1.name+"\n"); sb.append("\n"+st1.capital); sb.append("\n"+st2.capital); sb.append("\n"+st3.capital); maintext.settext(sb.tostring);
now problem every time comes correct answer in first line... how avoid ?
put correct answer in random spot using java's random
class
random.nextint(3)
give random number between 0 , 2. put correct answer array of size 3 @ location , put 2 wrong answers in remaining locations. loop through array , sb.append(array[i]);
(i between 0 , 2) random ordering of state capitals.
Comments
Post a Comment