Unquote capstone project

Hello everyone!
I am having a problem with my final capstone project. My correct answers are not adding up and I always get the 0 answer correct. Any help pointing me in the right direction will be appreciated.
Here is my MainActivity code:
package com.mrjay.unquotetest3;

/* COPY: Begin here */

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

int currentQuestionIndex;
int totalCorrect;
int totalQuestions;
ArrayList<Question> questions;

// TODO 3-A: Declare View member variables
ImageView questionImageView;
TextView questionTextView;
TextView questionsRemainingTextView;
Button answer0Button;
Button answer1Button;
Button answer2Button;
Button answer3Button;
Button submitButton;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // TODO 2-G: Show app icon in ActionBar
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setLogo(R.drawable.ic_unquote_icon);
    getSupportActionBar().setDisplayUseLogoEnabled(true);
    getSupportActionBar().setElevation(0);
    setContentView(R.layout.activity_main);

    // TODO 3-B: assign View member variables
    questionImageView = findViewById(R.id.iv_main_question_image);
    questionTextView = findViewById(R.id.tv_main_question_title);
    questionsRemainingTextView = findViewById(R.id.tv_main_questions_remaining_count);
    answer0Button = findViewById(R.id.btn_main_answer_0);
    answer1Button = findViewById(R.id.btn_main_answer_1);
    answer2Button = findViewById(R.id.btn_main_answer_2);
    answer3Button = findViewById(R.id.btn_main_answer_3);
    submitButton = findViewById(R.id.btn_main_submit_answer);


    // TODO 4-E: set onClickListener for each answer Button
    answer0Button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
                onAnswerSelected(0);
            }
    });
    answer1Button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick (View view){
                onAnswerSelected(1);
            }
    });
    answer2Button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick (View view){
                onAnswerSelected(2);
            }
    });
    answer3Button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick (View view){
                onAnswerSelected(3);
            }
    });

    // TODO 5-A: set onClickListener for the submit answer Button
    submitButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onAnswerSubmission();

        }
    });
    startNewGame();
}

// TODO 3-F: displayQuestion(Question question) {...}
    public void displayQuestion(Question question){
        questionImageView.setImageResource(question.imageId);
        questionTextView.setText(question.questionText);
        answer0Button.setText(question.answer0);
        answer1Button.setText(question.answer1);
        answer2Button.setText(question.answer2);
        answer3Button.setText(question.answer3);

    }

// TODO 3-C: displayQuestionsRemaining(int questionRemaining) {...}
    public void displayQuestionsRemaining(int questionsRemaining) {
        questionsRemainingTextView.setText(String.valueOf(questionsRemaining));
    }
// TODO 4-A: onAnswerSelected(int answerSelected) {...}
    public void onAnswerSelected(int answerSelected){
        Question currentQuestion = getCurrentQuestion();
        currentQuestion.playerAnswer = answerSelected;
        answer0Button.setText(currentQuestion.answer0);
        answer1Button.setText(currentQuestion.answer1);
        answer2Button.setText(currentQuestion.answer2);
        answer3Button.setText(currentQuestion.answer3);

        switch (answerSelected){
            case 0:
                answer0Button.setText("✔ " + currentQuestion.answer0);
                break;
            case 1:
                answer1Button.setText("✔ " + currentQuestion.answer1);
                break;
            case 2:
                answer2Button.setText("✔ " + currentQuestion.answer2);
                break;
            case 3:
                answer3Button.setText("✔ " + currentQuestion.answer3);
                break;
        }
    }

public void onAnswerSubmission() {
    Question currentQuestion = getCurrentQuestion();
    if (currentQuestion.isCorrect()) {
        totalCorrect++;
    }
    if(currentQuestion.playerAnswer == -1){
        return;
    }
    questions.remove(currentQuestion);

    // TODO 3-D.i: Uncomment the line below after implementing displayQuestionsRemaining(int)
    displayQuestionsRemaining(questions.size());

    if (questions.size() == 0) {
        String gameOverMessage = getGameOverMessage(totalCorrect, totalQuestions);

        // TODO 5-D: Show a popup instead
        AlertDialog.Builder gameOverDialogBuilder = new AlertDialog.Builder(MainActivity.this);
        gameOverDialogBuilder.setCancelable(false);
        gameOverDialogBuilder.setTitle("Game Over!");
        gameOverDialogBuilder.setMessage(gameOverMessage);
        gameOverDialogBuilder.setPositiveButton("Play again!", new DialogInterface.OnClickListener() {
           @Override
           public void onClick(DialogInterface dialog, int which) {
               startNewGame();
           }
       });
       gameOverDialogBuilder.create().show();
    } else {
        chooseNewQuestion();

        // TODO 3-H.i: uncomment after implementing displayQuestion(Question)
        displayQuestion(getCurrentQuestion());
    }
}

void startNewGame() {
    questions = new ArrayList<>();

    // TODO 2-H: Provide actual drawables for each of these questions!
    Question question0 = new Question(R.drawable.img_quote_0, "Pretty good advice, and perhaps a scientist did say it… Who actually did?", "Albert Einstein", "Issac Newton", "Rita Mae Brown", "Rosalind Franklin", 2);
    Question question1 = new Question(R.drawable.img_quote_1, "Was honest Abe honestly quoted? Who authored this pithy bit of wisdom?", "Edward Stieglitz", "Maya Angelou", "Abraham Lincoln", "Ralph Waldo Emerson", 0);
    Question question2 = new Question(R.drawable.img_quote_2, "Easy advice to read, difficult advice to follow — who actually said it?", "Martin Luther King Jr.", "Mother Teresa", "Fred Rogers", "Oprah Winfrey", 1);
    Question question3 = new Question(R.drawable.img_quote_3, "Insanely inspiring, insanely incorrect (maybe). Who is the true source of this inspiration?", "Nelson Mandela", "Harriet Tubman", "Mahatma Gandhi", "Nicholas Klein", 3);
    Question question4 = new Question(R.drawable.img_quote_4, "A peace worth striving for — who actually reminded us of this?", "Malala Yousafzai", "Martin Luther King Jr.", "Liu Xiaobo", "Dalai Lama", 1);
    Question question5 = new Question(R.drawable.img_quote_5, "Unfortunately, true — but did Marilyn Monroe convey it or did someone else?", "Laurel Thatcher Ulrich", "Eleanor Roosevelt", "Marilyn Monroe", "Queen Victoria", 0);

    questions.add(question0);
    questions.add(question1);
    questions.add(question2);
    questions.add(question3);
    questions.add(question4);
    questions.add(question5);

    totalCorrect = 0;
    totalQuestions = questions.size();



    while(questions.size() > 6){
        int randomIndex = generateRandomNumber(questions.size());
        questions.remove(randomIndex);
    }
    Question firstQuestion = chooseNewQuestion();

    // TODO 3-D.ii: Uncomment the line below after implementing displayQuestionsRemaining(int)
    displayQuestionsRemaining(questions.size());

    // TODO 3-H.ii: Uncomment after implementing displayQuestion(Question)
    displayQuestion(firstQuestion);
}

Question chooseNewQuestion() {
    int newQuestionIndex = generateRandomNumber(questions.size());
    currentQuestionIndex = newQuestionIndex;
    return questions.get(currentQuestionIndex);
}

int generateRandomNumber(int max) {
    double randomNumber = Math.random();
    double result = max * randomNumber;
    return (int) result;
}

Question getCurrentQuestion() {
    Question currentQuestion = questions.get(currentQuestionIndex);
    return currentQuestion;
}

String getGameOverMessage(int totalCorrect, int totalQuestions) {
    if (totalCorrect == totalQuestions) {
        return "You got all " + totalQuestions + " right! You won!";
    } else {
        return "You got " + totalCorrect + " right out of " + totalQuestions + ". Better luck next time!";
    }
}

}

/* COPY: End here */

Do you have a link to the particular course/path?

I believe this is it…
Cumulative Project: Capstone | Codecademy

Thank you

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.