Java Arrays and Loops Game Logic Pt. II

I need help because I keep getting this error!

MainActivity.java:34: error: illegal start of expression
    public Question chooseNewQuestion(){
    ^
1 error

This is my code for MainActivity.java. The error is where the comment says TODO #4

import java.util.ArrayList;

public class MainActivity {

    // TODO #1: add integer member variables here
    int currentQuestionIndex;
    int totalCorrect;
    int totalQuestions;

    // TODO #2: add ArrayList member variable here
    ArrayList<String> questions;
    // TODO #3 add startNewGame() here    
    public void startNewGame(){
      Question question1 = new Question(921238, "How tall is the Eiffel tower?", "1024 ft", "1034 ft", "1064 ft", "1124 ft", 1);
      Question question2 = new Question(921238, "How tall is Mt Everest?", "1024 ft", "1034 ft", "1064 ft", "1124 ft", 2);
      Question question3 = new Question(921238, "How tall is the OxBell Tower in Detective Conan?", "1024 ft", "1034 ft", "1064 ft", "1124 ft", 1);

      questions = new ArrayList<String>();
      questions.add(question1);
      questions.add(question2);
      questions.add(question3);

      int totalCorrect = 0;
      int totalQuestions = 0;

      Question firstQuestion = chooseNewQuestion(); 
      // displayQuestion(firstQuestion);
      // displayQuestionsRemaining(questions.size());

  
    
    
    // TODO #4 add chooseNewQuestion() here
    public Question chooseNewQuestion(){
      int randomQuestion = generateRandomNumber(questions.size()-1);
      currentQuestionIndex = randomQuestion;
      return questions.get(currentQuestionIndex);
      
    }
    // TODO #5 add getCurrentQuestion() here
    public Question getCurrentQuestion(){
      return questions.get(currentQuestionIndex);
    }
    // TODO #6 add onAnswerSubmission() here
    public void onAnswerSubmission(){
      Question currentQues = getCurrentQuestion();
      if (currentQues.isCorrect()){
        totalCorrect += 1;
        questions.remove(1);

        // displayQuestionsRemaining(questions.size());

        if(questions.size() == 0){
         System.out.println("game over");
         startNewGame();
          
        } else{
          chooseNewQuestion();
        }
      
      }
      // TODO: uncomment after implementing displayQuestion()
// displayQuestion(getCurrentQuestion());

    }

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

    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!";
        }
    }
}
public void startNewGame(){ // no matching } to close the method

you forgot to close the startNewGame method.

7 posts were split to a new topic: Java Arrays and Loops Game Logic pt. II