This must be a pretty simple fix, I've been working on this for a couple hours now, as I'm new to Java. So, why isn't the program continuing after I select the my 'yes' option to continue? It just idles.. the browse file input for the keyfile with one of two passwords [beep11, or beep22] is supposed to pop up, the user then picks the file, and it gives the output. Here's the code.
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.Scanner;
import javax.swing.JFileChooser;
public class TxtKeyVerifier2 {
public static void main(String[] args) throws FileNotFoundException {
Scanner keyboard = new Scanner(System.in);
System.out.print("Do you to continue yes/no: ");
String answer = keyboard.nextLine();
switch (answer) {
case "yes":
case "y":
{
JFileChooser fileChooser = new JFileChooser(".");
fileChooser.showOpenDialog(null);
File keyfile = fileChooser.getSelectedFile();
Scanner sc = new Scanner(keyfile);
String input = sc.nextLine();
if (authenticate1(input)) {
System.out.println("This program is working if this text is found within outputfile.txt.");
File outputfile = new File("outputfile.txt");
FileOutputStream fos = new FileOutputStream(outputfile);
PrintStream ps = new PrintStream(fos);
System.setOut(ps);
System.out.println("This program is working if this text is found within outputfile.txt.");
}else if (authenticate2(input)) {
System.out.println("It works.");
}else{
System.out.println("Error: Wrong password.");
}
}
break;
case "no":
case "n":
break;
default:
System.out.println("Invalid choice");
}
}
private static boolean authenticate1(String password1) {
return ((password1.length() == 6)
&& (password1.matches("beep11"))
&& (password1.matches("beep11"))
&& (password1.matches("beep11")));
}
private static boolean authenticate2(String password2) {
return ((password2.length() == 6)
&& (password2.matches("beep22"))
&& (password2.matches("beep22"))
&& (password2.matches("beep22")));
}
}