I have a simple quiz app with 5 radio buttons and 5 checkbox. The checkbox question have multiple answers , for such one question there are 3 right answers out of 4 checkbox. When user selects the wrong one among three boxes the score is still getting incremented, how to not increment for wrong selection checkbox.
MainActivity :
[public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
/**
* The number of correct answers
*/
int score = 0;
public void end_Test(View view) {
EditText nameField = findViewById(R.id.name_field);
String name = nameField.getText().toString();
//Called question checking methods
question_1();
question_2();
question_3();
question_4();
question_5();
question_6();
question_7();
question_8();
question_9();
question_10();
// Display the test result on the screen
String test_result = createTestResult(name, score);
displayResult(test_result);
// Disabled "End Test" button after clicking on it.
Button endTestButton = findViewById(R.id.end_test_button);
endTestButton.setEnabled(false);
}
public void question_10() {
// Figure out if the user chose "Ipad" answer
CheckBox IpadCheckBox = findViewById(R.id.ipad_checkbox);
boolean hasIpad = IpadCheckBox.isChecked();
// Figure out if the user chose "Imac" answer
CheckBox ImacCheckBox = findViewById(R.id.imac_checkbox);
boolean hasImac = ImacCheckBox.isChecked();
// Figure out if the user chose "Ipod" answer
CheckBox IpodCheckBox = findViewById(R.id.ipod_checkbox);
boolean hasIpod = IpodCheckBox.isChecked();
// Figure out if the user chose "Ipod" answer
CheckBox ImaxCheckBox = findViewById(R.id.imax_checkbox);
ImaxCheckBox.isChecked();
if (hasIpad) {
if (hasImac){
if (hasIpod){
increment_score();
}
}
}
}
/**
* This method is called when user selected the correct answer.
* Added +1 to score for each correct answer
*/
private int increment_score() {
score = ++score;
return score;
}
}][1]
Aucun commentaire:
Enregistrer un commentaire