import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
 
public class Main {
    public static void main(String[] args) {
        int state = 0;
        char input = 0;
 
        int table[][] = {
            {1,0,0}, // state 0
            {1,2,1} // state 1
        };
 
        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 (input) {
                    case 'a':
                        state = table[state][0];
                    break;
                    case 'b':
                        state = table[state][1];
                    break;
                    case 'c':
                        state = table[state][2];
                    break;
                    default:
                        System.out.println("Invalid input received.");
                    break;
                }
                System.out.println("Current state: " + state);
            }
        }
        System.out.println("Machine operation completed.");
    }
}