I'm trying to create a simple application that takes in a certain number of names and creates tournament brackets from them. Right now I'm stuck creating the number of matches and contestants per match. As it stands, I want to create a failsafe that will warn the user if the number of people they want in a match does not divide evenly with the total number of people. I ask them to simply enter either 'Y' or 'N' to dictate this. The problem is that the program does not give them the chance to enter their response and automatically spits out a NoSuchElementFound exception: No line found.
This is a brand new scanner made to take in this response. I tried using .hasNext in order to see if there is no next line, and the result it gets is false. Essentially, after I've gotten all of the contestants (a separate method that works fine) this is the console:
Total Number of Contestants: 5
How many contestants do you want to compete per match?
2
Warning: Choosing this number means that there will not be the same number of contestants in each match.
Reminder that the total number of contestants is: 5
If you want to proceed, enter 'Y'. If you want to enter a different number of contestants per match, enter 'N'.
check value: false
If it helps, this is the troublesome code:
String answer = "yes";
Scanner scan = new Scanner(System.in);
float roundedMatchCount = 0;
float matchCount = 0;
entrant victor = new entrant();
float matchMembers;
Scanner scan = new Scanner(System.in);
System.out.println("How many contestants do you want to compete per match?");
matchMembers = scan.nextInt();
matchCount = input.size() / matchMembers;
scan.close();
Scanner s = new Scanner(System.in);
if (input.size() % matchMembers !=0)
//if the number of contestants is not divisble by the number
//of participants in a match
{
System.out.println("Warning: Choosing this number means that there will not be the same number of contestants in each match.");
System.out.println("Reminder that the total number of contestants is: "
+input.size());
//begin while
System.out.println("If you want to proceed, enter 'Y'. If you want to enter a different number of contestants per match, enter 'N'.");
boolean check = s.hasNextLine();
System.out.println("check value: " + check);
answer = s.nextLine();
//WHAT
if (answer.contains("N"))
{
//ask for a new number
}
else if (answer.contains("Y"))
{
//round the number of matches up or down depending on user input
}
else
{
System.out.println("Error: Invalid response.");
}
}
Please note that input is an ArrayList that was passed into this method from the previous one. I know that the correct number of entries is inside it because in previous tests I had its contents and size printed out.