0

Long time admirer, first time poster :)

Hi all, I suspect that the question needs further explanation as this may potentially be a catastrophic design flaw in my first attempt at a Java quiz.

The game is this... user is asked a maths question, then given a choice of 3 and must input 1, 2 or 3 as their answer...this is then to be compared to the ACTUAL answer and then the users' score is incremented/decremented by one.

So far, I have everything in place that will generate the random bits to construct the question along with fake answers and the correct sum.

I am up to the point where the user chooses 1,2 or 3...I have the if statement and everything.

So now the context has been set, this is fundamental the problem...

User sees on the screen...

"What is... 32-83 (1): -51 (2): -55 (3): -48

Please enter your selection:"

If the user presses say 2 which is the incorrect answer, how do I capture the '-55' bit, if I could do that I suspect I could do a compare on the return which provides me with the right answer (a simple bool compare perhaps).

This is my first attempt at putting Java to use :)

Thanks in advance!

Ah, probably worth mentioning that this is the code that generates the question to be shown on screen...

public String generateQuestionOnScreen(){

    String s = "What is... "+l+""+c+""+r;
    return s;
    }

..and this shows the options..

public void generateOptionsOnScreen(){
    int array[]=new int[3];
array[0]=result;
array[1]=fake1;
array[2]=fake2;

System.out.println("(1): "+result);
    System.out.println("(2): "+fake1);
    System.out.println("(3): "+fake2);

}
sherbert
  • 362
  • 1
  • 4
  • 16

1 Answers1

0

You should be able to capture the value that the user entered on the keyboard through a library function. You would take that result and then do a comparison.

This question may help: Java: How to get input from System.console() .

Note: I think you want to do a compare that the result is "2", not "-55" in your example.

Community
  • 1
  • 1
J. Polfer
  • 12,251
  • 10
  • 54
  • 83
  • So, it appears that there was some re-architecting needed. it appears that what I should have done is generated the number of the question dynamically and also the answer/fakes seperately and then combined them. – sherbert Apr 01 '13 at 15:06
  • Agreed, I definately need to do a compare on '2' and not '-55' – sherbert Apr 01 '13 at 15:11
  • @sherbert - I personally thought this was an okay question, but I strongly suspected other mods would close it, and they did. I would encourage you to look through the questions I've asked. I've rarely had mine closed. They should give you a better idea of how to ask next time to prevent a closed question. – J. Polfer Apr 01 '13 at 19:58