My code compiles but once I run it, it asks for user input and then stops. However, the program says it's still running but it doesn't move on to execute the rest of the code and I can't figure out why.
Here's a portion of my code. It stops after I ask the user how many questions they would like to answer. According to my debugger, it specifically stops at "qNum = console.nextInt();" when I enter in a valid input.
import java.util.*;
import java.io.*;
public class QuizBowlRedo implements Quiz {
private Player player; // player object
private String file; // name of file
private int qNum; // number of questions player wants to answer
private int qNumFile; // number of questions in file
private ArrayList<Question> questionsArr; // holds Question objects
private boolean questionsAsked[];
// Constructor
public QuizBowlRedo(String fName, String lName, String file) throws FileNotFoundException {
player = new Player(fName, lName);
Scanner gameFile = new Scanner(new File(file));
qNum = numOfQuestionsToPlay();
qNumFile = maxNumQFile(gameFile);
questionsArr = new ArrayList<Question>();
readFile();
questionsAsked = new boolean[qNumFile];
}
// asks user how many questions to ask
public int numOfQuestionsToPlay() {
Scanner console = new Scanner(System.in);
// CHECKS FOR VALID USER INPUT
boolean check = false;
do {
try {
System.out.print("How many questions would you like (out of 3)? ");
if(console.nextInt() > 3) {
System.out.println("Sorry, that is too many.");
check = false;
}
else {
check = true;
qNum = console.nextInt();
}
}
catch(InputMismatchException e) {
System.out.println("Invalid input. Please try again.");
console.nextLine();
check = false;
}
}
while(check == false);
return qNum;
}