• Post Reply Bookmark Topic Watch Topic
  • New Topic

Calculating score of Quiz game  RSS feed

 
Sidra Shah Shah
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have quiz type program where I have used three radio buttons i-e choiceOne, choiceTwo and Correctchoice with a buttonGroup.

                        c1.setText(Question.get(i).getChoiceOne());
                        c2.setText(Question.get(i).getCorrectChoice());
                        c3.setText(Question.get(i).getChoiceTwo());
For making the choices to appear random I have used the following code:

     String one = Question.get(i).getChoiceOne();
    String two = Question.get(i).getChoiceTwo();
    String three = Question.get(i).getCorrectChoice();
    List<String> choices = Arrays.asList(one, two, three);
    Collections.shuffle(choices);
    c1.setText(choices.get(0).toString());
    c2.setText(choices.get(1).toString());
    c3.setText(choices.get(2).toString());
Now I want to calculate the user score/points so how can I find the right answer from it to calculate the score? Also what is the appropriate way to calculate i-e should I use a variable which needs to increment or use a separate class for it and use setter/getter methods? Any guidance should be appreciated?
 
Campbell Ritchie
Marshal
Posts: 55772
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

You appear to have a Question class, which is good, but do you have a flag to mark which is the correct answer? Then you can do the shuffling inside the Question class and fulfil the single responsibility principle.
Similarly you should have a Quiz class which asks the questions in turn and maintains the score, maybe as a field of the Quiz class.
 
Sidra Shah Shah
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi, thanks for your reply but I did not get you. Can you please come with a short example?
regards
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!