Challenge:Who have solutions to give a percentage score

Challenge:When the user has answered all the questions, he displays a toast message and gives the percentage form

Hi,evrybody:
I am actually working through this great book and am solving now the second challenge exercises of chapter 3,and the title is: when the user has finished all, he displays a toast message and gives a percentage score .
But i have no idea about this,as toast messages should not be String type?

You can show toasts with strings too. You can use either a resource ID or a string value.

This version of makeText can operate off of a String value: https://developer.android.com/reference/android/widget/Toast.html#makeText(android.content.Context, java.lang.CharSequence, int).

Thanks,I’ll try.It’s really a good book to improve myself.

I can’t open this link.
can you share code in this net?
Thank you !

Here is my solution for the two challenges in chapter 3. The code is marked.

package com.bignerdranch.android.geoquiz;

…
// challenge 3.1
import java.util.ArrayList;

public class QuizActivity extends AppCompatActivity {

private static final String TAG = "QuizActivity";
private static final String KEY_INDEX = "index";

private Button mTrueButton;
private Button mFalseButton;
private Button mNextButton;
private TextView mQuestionTextView;
// challenge 3.1
private ArrayList<Integer> mQuestionAsked = new ArrayList<Integer>(6);
// challenge 3.2
private int mTrueAnswer = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(TAG, “onCreate(Bundle) called”);
setContentView(R.layout.activity_quiz);

    if (savedInstanceState != null) {
        mCurrentIndex = savedInstanceState.getInt(KEY_INDEX, 0);
        // challenge 3.1
        mQuestionAsked = savedInstanceState.getIntegerArrayList("myArray");
    }

    mQuestionTextView = (TextView) findViewById(R.id.question_text_view);
    mQuestionTextView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mCurrentIndex = (mCurrentIndex + 1) % mQuestionBank.length;
            updateQuestion();
        }
    });

…

private void updateQuestion() {
    int question = mQuestionBank[mCurrentIndex].getTextResId();
    mQuestionTextView.setText(question);

    /* challenge 3.1................*/
    mFalseButton.setVisibility(View.VISIBLE);
    mTrueButton.setVisibility(View.VISIBLE);

    for (Integer i = 0; i < mQuestionAsked.size(); i++) {
        if (mCurrentIndex == mQuestionAsked.get(i)) {
            mFalseButton.setVisibility(View.INVISIBLE);
            mTrueButton.setVisibility(View.INVISIBLE);
        }
    }
    /*...............................*/
    // challenge 3.2
    int resultResId = (mTrueAnswer*100) / 6;
    if (mQuestionAsked.size() > 5) {
        Toast.makeText(this, Integer.toString(resultResId)+"% correct answers", Toast.LENGTH_LONG)
                .show();
    }
}

 @Override
protected void onSaveInstanceState(Bundle savedInstanceState) {
    super.onSaveInstanceState(savedInstanceState);
    Log.i(TAG, "onSaveInstanceState");
    savedInstanceState.putInt(KEY_INDEX, mCurrentIndex);
    // challenge 3.1
    savedInstanceState.putIntegerArrayList("myArray", mQuestionAsked);
}

private void checkAnswer(boolean userPressedTrue) {
    boolean answerIsTrue = mQuestionBank[mCurrentIndex].isAnswerTrue();

    // challenge 3.1
    mQuestionAsked.add(mCurrentIndex);
    mFalseButton.setVisibility(View.INVISIBLE);
    mTrueButton.setVisibility(View.INVISIBLE);
    /*...............................*/

    int messageResId = 0;

    if (userPressedTrue == answerIsTrue) {
        messageResId = R.string.correct_toast;
        // challenge 3.2
        mTrueAnswer = mTrueAnswer + 1;
    } else {
        messageResId = R.string.incorrect_toast;
    }
    Toast.makeText(this, messageResId, Toast.LENGTH_SHORT)
            .show();
}

}

My solution:

...
private int correctAnswers = 0;
...

private void checkAnswer(boolean userPressedTrue) {
    questionsAnswered[currentIndex] = true;
    setButtonsEnabled(false);

    boolean answerIsTrue = questionBank[currentIndex].isAnswerTrue();

    int messageResId;

    if (userPressedTrue == answerIsTrue) {
        messageResId = R.string.toast_correct;
        correctAnswers++;
    } else {
        messageResId = R.string.toast_incorrect;
    }

    Toast.makeText(this, messageResId, Toast.LENGTH_SHORT).show();
    calculateScore();
}

private void calculateScore() {
    // check all questions answered
    for (boolean answered : questionsAnswered) {
        if (!answered) return;
    }
    // all answered, show message
    int score = correctAnswers * 100 / questionBank.length;
    String message = getString(R.string.toast_score, score);
    Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
}

And my strings.xml with placeholder

<resources>
    ...
    <string name="toast_score">You have %1$d%% correct answers!</string>
    ...
</resources>
1 Like

My solution for both challenges

Comments are encouraged

public&#32;class&#32;QuizActivity&#32;extends&#32;AppCompatActivity&#32;{

&#32;&#32;&#32;&#32;private&#32;static&#32;final&#32;String&#32;KEY_INDEX&#32;=&#32;"index";
&#32;&#32;&#32;&#32;private&#32;static&#32;final&#32;String&#32;KEY_SCORE&#32;=&#32;"score";
&#32;&#32;&#32;&#32;private&#32;static&#32;final&#32;String&#32;KEY_ANSWERED&#32;=&#32;"answered";

&#32;&#32;&#32;&#32;private&#32;static&#32;final&#32;int&#32;QUESTION_GRADE&#32;=&#32;1;

&#32;&#32;&#32;&#32;private&#32;Button&#32;mTrueButton;
&#32;&#32;&#32;&#32;private&#32;Button&#32;mFalseButton;
&#32;&#32;&#32;&#32;private&#32;Button&#32;mNextButton;
&#32;&#32;&#32;&#32;private&#32;Button&#32;mPrevButton;
&#32;&#32;&#32;&#32;private&#32;TextView&#32;mQuestionTextView;

&#32;&#32;&#32;&#32;private&#32;Question[]&#32;mQuestionBank&#32;=&#32;new&#32;Question[]{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;new&#32;Question(R.string.question_australia,&#32;true),
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;new&#32;Question(R.string.question_oceans,&#32;true),
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;new&#32;Question(R.string.question_middleeast,&#32;false),
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;new&#32;Question(R.string.question_africa,&#32;false),
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;new&#32;Question(R.string.question_americas,&#32;true),
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;new&#32;Question(R.string.question_asia,&#32;true),
&#32;&#32;&#32;&#32;};

&#32;&#32;&#32;&#32;private&#32;int&#32;mCurrentIndex&#32;=&#32;0;

&#32;&#32;&#32;&#32;private&#32;boolean[]&#32;mQuestionStatus&#32;=&#32;new&#32;boolean[mQuestionBank.length];
&#32;&#32;&#32;&#32;private&#32;int[]&#32;mScore&#32;=&#32;new&#32;int[mQuestionBank.length];

&#32;&#32;&#32;&#32;@Override
&#32;&#32;&#32;&#32;protected&#32;void&#32;onCreate(Bundle&#32;savedInstanceState)&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;super.onCreate(savedInstanceState);
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;setContentView(R.layout.activity_quiz);

&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;if&#32;(savedInstanceState&#32;!=&#32;null)&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;mCurrentIndex&#32;=&#32;savedInstanceState.getInt(KEY_INDEX);

&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;if&#32;(savedInstanceState.containsKey(KEY_ANSWERED))&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;mQuestionStatus&#32;=&#32;savedInstanceState.getBooleanArray(KEY_ANSWERED);
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;}

&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;if&#32;(savedInstanceState.containsKey(KEY_SCORE))&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;mScore&#32;=&#32;savedInstanceState.getIntArray(KEY_SCORE);
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;}
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;}

&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;//&#32;question&#32;text&#32;view
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;mQuestionTextView&#32;=&#32;(TextView)&#32;findViewById(R.id.question_text_view);
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;/*
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;mQuestionTextView.setOnClickListener(new&#32;View.OnClickListener()&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;@Override
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;public&#32;void&#32;onClick(View&#32;view)&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;nextQuestion();
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;}
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;});
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;*/

&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;//&#32;True&#32;button
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;mTrueButton&#32;=&#32;(Button)&#32;findViewById(R.id.true_button);
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;mTrueButton.setOnClickListener(new&#32;View.OnClickListener()&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;@Override
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;public&#32;void&#32;onClick(View&#32;view)&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;checkAnswer(true);
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;}
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;});

&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;//&#32;False&#32;button
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;mFalseButton&#32;=&#32;(Button)&#32;findViewById(R.id.false_button);
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;mFalseButton.setOnClickListener(new&#32;View.OnClickListener()&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;@Override
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;public&#32;void&#32;onClick(View&#32;view)&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;checkAnswer(false);
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;}
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;});

&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;//&#32;Next&#32;button
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;mNextButton&#32;=&#32;(Button)&#32;findViewById(R.id.next_button);
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;mNextButton.setOnClickListener(new&#32;View.OnClickListener()&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;@Override
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;public&#32;void&#32;onClick(View&#32;view)&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;nextQuestion();
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;}
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;});

&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;//&#32;Previous&#32;button
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;mPrevButton&#32;=&#32;(Button)&#32;findViewById(R.id.previous_button);
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;mPrevButton.setOnClickListener(new&#32;View.OnClickListener()&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;@Override
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;public&#32;void&#32;onClick(View&#32;view)&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;previousQuestion();
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;}
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;});

&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;//&#32;At&#32;app&#32;run,&#32;display&#32;the&#32;first&#32;question
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;updateQuestion();
&#32;&#32;&#32;&#32;}

&#32;&#32;&#32;&#32;@Override
&#32;&#32;&#32;&#32;public&#32;void&#32;onStart()&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;super.onStart();
&#32;&#32;&#32;&#32;}

&#32;&#32;&#32;&#32;@Override
&#32;&#32;&#32;&#32;public&#32;void&#32;onResume()&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;super.onResume();
&#32;&#32;&#32;&#32;}

&#32;&#32;&#32;&#32;@Override
&#32;&#32;&#32;&#32;public&#32;void&#32;onPause()&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;super.onPause();
&#32;&#32;&#32;&#32;}

&#32;&#32;&#32;&#32;@Override
&#32;&#32;&#32;&#32;public&#32;void&#32;&#32;onSaveInstanceState(Bundle&#32;savedInstanceState)&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;super.onSaveInstanceState(savedInstanceState);
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;savedInstanceState.putInt(KEY_INDEX,&#32;mCurrentIndex);
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;savedInstanceState.putBooleanArray(KEY_ANSWERED,&#32;mQuestionStatus);
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;savedInstanceState.putIntArray(KEY_SCORE,&#32;mScore);
&#32;&#32;&#32;&#32;}

&#32;&#32;&#32;&#32;@Override
&#32;&#32;&#32;&#32;public&#32;void&#32;onStop()&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;super.onStop();
&#32;&#32;&#32;&#32;}

&#32;&#32;&#32;&#32;@Override
&#32;&#32;&#32;&#32;public&#32;void&#32;onDestroy()&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;super.onDestroy();
&#32;&#32;&#32;&#32;}

&#32;&#32;&#32;&#32;/*
&#32;&#32;&#32;&#32;&#32;*&#32;Updates&#32;the&#32;text&#32;view&#32;with&#32;the&#32;question&#32;statement
&#32;&#32;&#32;&#32;&#32;*&#32;corresponding&#32;to&#32;current&#32;index
&#32;&#32;&#32;&#32;&#32;*/
&#32;&#32;&#32;&#32;private&#32;void&#32;updateQuestion()&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;int&#32;question&#32;=&#32;mQuestionBank[mCurrentIndex].getTextResId();
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;mQuestionTextView.setText(question);

&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;//&#32;if&#32;question&#32;has&#32;not&#32;been&#32;answered&#32;already,&#32;activate&#32;answer&#32;buttons
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;if&#32;(!mQuestionStatus[mCurrentIndex&#32;%&#32;mQuestionBank.length])&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;activateAnswerButton();
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;}&#32;else&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;deactivateAnswerButton();
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;}
&#32;&#32;&#32;&#32;}

&#32;&#32;&#32;&#32;/*
&#32;&#32;&#32;&#32;&#32;*&#32;Display&#32;a&#32;toast&#32;message&#32;indicating&#32;correctness&#32;of&#32;user&#32;answer
&#32;&#32;&#32;&#32;&#32;*&#32;@param&#32;userPressedTrue&#32;A&#32;falg&#32;indicating&#32;whether&#32;the&#32;user&#32;answered&#32;True
&#32;&#32;&#32;&#32;&#32;*/
&#32;&#32;&#32;&#32;private&#32;void&#32;checkAnswer(boolean&#32;userPressedTrue)&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;//&#32;Mark&#32;question&#32;as&#32;answered
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;mQuestionStatus[mCurrentIndex&#32;%&#32;mQuestionBank.length]&#32;=&#32;true;

&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;deactivateAnswerButton();

&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;int&#32;toastResId;

&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;boolean&#32;isCorrectAnswer&#32;=&#32;userPressedTrue&#32;==&#32;mQuestionBank[mCurrentIndex].isAnswerTrue();
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;if&#32;(isCorrectAnswer)&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;mScore[mCurrentIndex&#32;%&#32;mQuestionBank.length]&#32;=&#32;QUESTION_GRADE;
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;toastResId&#32;=&#32;R.string.correct_toast;
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;}&#32;else&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;//&#32;when&#32;user&#32;answered&#32;again,&#32;report&#32;his&#32;inccorect&#32;answeres(depend&#32;on&#32;business&#32;logic)
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;mScore[mCurrentIndex&#32;%&#32;mQuestionBank.length]&#32;=&#32;0;
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;toastResId&#32;=&#32;R.string.incorrect_toast;
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;}

&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;Toast&#32;toast&#32;=&#32;Toast.makeText(QuizActivity.this,&#32;toastResId,
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;Toast.LENGTH_LONG);
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;toast.setGravity(Gravity.BOTTOM,&#32;0,&#32;0);
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;toast.show();

&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;if&#32;(allAnswered())&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;DisplayScore();
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;reset();
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;}
&#32;&#32;&#32;&#32;}

&#32;&#32;&#32;&#32;/*
&#32;&#32;&#32;&#32;&#32;*&#32;Checks&#32;whether&#32;the&#32;user&#32;has&#32;answered&#32;all&#32;the&#32;questions
&#32;&#32;&#32;&#32;&#32;*&#32;@return&#32;true&#32;if&#32;the&#32;user&#32;has&#32;answered&#32;all&#32;questions
&#32;&#32;&#32;&#32;&#32;*/
&#32;&#32;&#32;&#32;private&#32;boolean&#32;allAnswered()&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;for&#32;(boolean&#32;status&#32;:&#32;mQuestionStatus)&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;if&#32;(!status)&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;return&#32;false;
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;}
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;}
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;return&#32;true;
&#32;&#32;&#32;&#32;}

&#32;&#32;&#32;&#32;/*
&#32;&#32;&#32;&#32;&#32;*&#32;Reset&#32;score&#32;and&#32;answered&#32;questions
&#32;&#32;&#32;&#32;&#32;*/
&#32;&#32;&#32;&#32;private&#32;void&#32;reset()&#32;{

&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;//&#32;set&#32;all&#32;questions&#32;unanswered
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;for&#32;(int&#32;i&#32;=&#32;0;&#32;i&#32;&lt;&#32;mQuestionStatus.length&#32;;&#32;i++)&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;mQuestionStatus[i]&#32;=&#32;false;
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;}

&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;//&#32;set&#32;all&#32;scores&#32;to&#32;zero
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;for&#32;(int&#32;i&#32;=&#32;0;&#32;i&#32;&lt;&#32;mScore.length&#32;;&#32;i++)&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;mScore[i]&#32;=&#32;0;
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;}
&#32;&#32;&#32;&#32;}

&#32;&#32;&#32;&#32;/*
&#32;&#32;&#32;&#32;&#32;*&#32;Displays&#32;the&#32;score
&#32;&#32;&#32;&#32;&#32;*/
&#32;&#32;&#32;&#32;private&#32;void&#32;DisplayScore()&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;Toast.makeText(this,
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;"Score:&#32;"&#32;+&#32;getScore()&#32;+&#32;"%",
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;Toast.LENGTH_LONG).show();
&#32;&#32;&#32;&#32;}

&#32;&#32;&#32;&#32;/*
&#32;&#32;&#32;&#32;&#32;*&#32;Gets&#32;the&#32;score&#32;as&#32;a&#32;percentage
&#32;&#32;&#32;&#32;&#32;*&#32;@return&#32;The&#32;score
&#32;&#32;&#32;&#32;&#32;*/
&#32;&#32;&#32;&#32;private&#32;double&#32;getScore()&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;double&#32;score&#32;=&#32;0;
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;for&#32;(int&#32;i&#32;=&#32;0;&#32;i&#32;&lt;&#32;mScore.length&#32;;&#32;i++)&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;score&#32;+=&#32;mScore[i];
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;}
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;return&#32;&#32;(score&#32;/&#32;mQuestionBank.length)&#32;*&#32;100;
&#32;&#32;&#32;&#32;}

&#32;&#32;&#32;&#32;/*
&#32;&#32;&#32;&#32;&#32;*&#32;Proceeds&#32;to&#32;next&#32;question
&#32;&#32;&#32;&#32;&#32;*/
&#32;&#32;&#32;&#32;private&#32;&#32;void&#32;nextQuestion()&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;//&#32;keep&#32;looping&#32;forward&#32;in&#32;the&#32;questions
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;mCurrentIndex&#32;=&#32;(mCurrentIndex&#32;+&#32;1)&#32;%&#32;mQuestionBank.length;
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;updateQuestion();
&#32;&#32;&#32;&#32;}

&#32;&#32;&#32;&#32;/*
&#32;&#32;&#32;&#32;&#32;*&#32;Returns&#32;to&#32;previous&#32;question
&#32;&#32;&#32;&#32;&#32;*/
&#32;&#32;&#32;&#32;private&#32;&#32;void&#32;previousQuestion()&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;//&#32;keep&#32;looping&#32;backward&#32;in&#32;the&#32;questions
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;if(mCurrentIndex&#32;==&#32;0)&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;mCurrentIndex&#32;=&#32;mQuestionBank.length&#32;-&#32;1;
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;}&#32;&#32;else&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;mCurrentIndex&#32;=&#32;mCurrentIndex&#32;-&#32;1;
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;}
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;updateQuestion();
&#32;&#32;&#32;&#32;}

&#32;&#32;&#32;&#32;/*
&#32;&#32;&#32;&#32;&#32;*&#32;Deactivates&#32;True&#32;and&#32;False&#32;buttons
&#32;&#32;&#32;&#32;&#32;*/
&#32;&#32;&#32;&#32;private&#32;void&#32;deactivateAnswerButton()&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;mTrueButton.setEnabled(false);
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;mFalseButton.setEnabled(false);
&#32;&#32;&#32;&#32;}

&#32;&#32;&#32;&#32;/*
&#32;&#32;&#32;&#32;&#32;*&#32;Activates&#32;True&#32;and&#32;False&#32;buttons
&#32;&#32;&#32;&#32;&#32;*/
&#32;&#32;&#32;&#32;private&#32;void&#32;activateAnswerButton()&#32;{
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;mTrueButton.setEnabled(true);
&#32;&#32;&#32;&#32;&#32;&#32;&#32;&#32;mFalseButton.setEnabled(true);
&#32;&#32;&#32;&#32;}
private int mTrueAnswer = 0;
private int mCurrentNumberAnswered = 0;

 private void updateQuestion(){
    mTrueButton.setEnabled(!mQuestionAnswered[mCurrentIndex]); 
    mFalseButton.setEnabled(!mQuestionAnswered[mCurrentIndex]);

    int question = mQuestionnBank[mCurrentIndex].getTextResId();
    mQuestionTextView.setText(question);
    **mCurrentNumberAnswered++;**

**int resultResId = (mTrueAnswer*100)/6;**
**        if(mCurrentNumberAnswered==mQuestionnBank.length+1){**
**            Toast.makeText(this, Integer.toString(resultResId)+"% correct answers", Toast.LENGTH_LONG).show();**
}
}

if(userPressedTrue == answerIsTrue){
messageResId = R.string.correct_toast;
mTrueAnswer = mTrueAnswer +1;

    }else{
        messageResId = R.string.incorrect_toast;
    }
    Toast.makeText(this,messageResId,Toast.LENGTH_SHORT).show();
}

I am trying to solve this challenge but I still don’t know what the toast message is not displayed.
Can anyone help please?
Below is my code:

private fun checkAnswer(userAnswer: Boolean) {

    binding.falseButton.isEnabled = false
    binding.trueButton.isEnabled = false
    questionBank[currentIndex].answered = true
    val correctAnswer = questionBank[currentIndex].answer
    val messageResId = if (userAnswer == correctAnswer) {
        R.string.correct_toast
    } else {
        R.string.incorrect_toast
    }
    if (isAllQuestionsAnswered()) {
        val score = getString(R.string.percentage_toast, calculateScore())
        Toast.makeText(this, score, Toast.LENGTH_SHORT).show()
    } else {
        Toast.makeText(this, messageResId, Toast.LENGTH_SHORT).show()
    }
    correctAnswers++
}

private fun isAnswered(index: Int) {
    val isQuestionAnswered = questionBank[index].answered
    binding.trueButton.isEnabled = !isQuestionAnswered
    binding.falseButton.isEnabled = !isQuestionAnswered

}

private fun isAllQuestionsAnswered(): Boolean {
    for (question in questionBank) {
        if (question.answered) {
            return false
        }
    }
    return true

}

private fun calculateScore():Double {
return (correctAnswers.toDouble() / questionBank.size) * 100
}