I have 2 questions. 1. I have problem to find a way going one step back in 'do, while loop' if user do not enter correct command into console. 2. After doing that, I want to use Users input in switch loop, so the chosen command can be processed, but I am not sure what to put into brackets as a variable to test, because it does not recognise Users input.
Here is what I have done so far. I've tried a lot of things, but non of them worked out.
`package assignment6;
public class Enumeracija {
public enum Commands {
PROPERTIES, NEW_FOLDER, RENAME, COPY, CUT, DELETE, UNSPECIFIED
}}
package assignment6;
import assignment6.Enumeracija.Commands;
import java.io.*;
import java.util.Scanner;
public class Assignment6 {
public static boolean main(String[] args) throws FileNotFoundException,
IOException {
//Showing commands to user
for (int i = 0; i<Commands.values().length-1; i++){
System.out.println(Commands.values()[i]);
}
//Reading users input
Scanner scan = new Scanner(System.in);
System.out.println("Enter one of the given commands: ");
String userInput;
/* WHILE DO LOOP so user can make a mistake and program will not stop
running, until he writes it correctly. But Im getting main class not
found problem, when I want to run it.*/
do {
userInput = scan.nextLine().trim().toUpperCase();
if (userInput.equals(Commands.values())) {
return true;}
else {
System.out.println("Input error. Keep trying and make sure you write command correctly.");
return false;}
} while (false);
switch(userInput) {
/*If I use userInput, it does not recognise commands
that user enters. Every case is being unrecognized.*/
case PROPERTIES:
//;
break;
case NEW_FOLDER:
//;
break;
case RENAME:
//;
break;
case COPY:
//;
break;
case CUT:
//;
break;
case DELETE:
//;
break;
case UNSPECIFIED:
//;
break;*/