I have a problem where once I select one of the four options with my scanner, it'll default to that switch case, so say I initially press 1, input my string of words, then press 2, it'll still execute as if I hit case 1. What have I done wrong here?
public static void menu()
{
FileClass f = new FileClass();
Scanner scan = new Scanner(System.in);
System.out.println("Choose an option");
System.out.println("1: Write To File\n2: Read From File\n3: Delete From File\n4: Exit Program");
int choice = scan.nextInt();
while(choice < 5) {
switch(choice) {
case 1:
System.out.println("Enter a line you wish to write to the file: ");
Scanner inputW = new Scanner(System.in);
String lineWrite = inputW.nextLine();
f.writeToFile(lineWrite);
break;
case 2:
System.out.println("This is Everything on the File:");
f.readFromFile();
break;
case 3:
System.out.println("Enter a line you wish to delete from the file: ");
Scanner inputD = new Scanner(System.in);
String lineDelete = inputD.nextLine();
f.deleteFromFile(lineDelete);
break;
case 4:
System.exit(0);
break;
}
System.out.println("Choose an option");
System.out.println("1: Write To File\n2: Read From File\n3: Delete From File\nExit Program");
scan.nextInt();
}
System.exit(0);
}