import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; public class Main { /* * Cool_Fire * opdracht 6.2.1 Autoswitch automaat */ public static void main(String[] args) { int state = 0; char input = 0; while(!(state == 2)) { try { System.out.print("Enter command (a, b or c): "); input = (char)System.in.read(); } catch (IOException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } if(!((int)input == 10)){ //ingnore newlines switch (state) { case 0: switch (input) { case 'a': state = 1; System.out.println("Progressing to state " + state + "."); break; case 'b': System.out.println("Option b is not useful in this state. Remaining is state " + state + "."); state = 0; break; case 'c': System.out.println("Option c is not useful in this (or any) state. Remaining in state " + state + "."); state = 0; break; default: System.out.println("Invalid input received."); break; } break; case 1: switch (input) { case 'a': System.out.println("Option a is not available in this state."); break; case 'b': state = 2; System.out.println("Progressing to state " + state + "."); break; case 'c': System.out.println("Option c is not useful in this (or any) state. Remaining in state " + state + "."); state = 1; break; default: System.out.println("Invalid input received."); break; } break; case 2: System.out.println("We should never reach this point. If we have, something has, in fact, gone terribly wrong."); break; default: System.out.println("The universe has stopped making sense. Please check your chair for alien limbs."); break; } } } System.out.println("Machine operation completed."); } }