src/Visualizer.java
/**
     * Handles user control of the Visualizer.
     */
Handles user control of the Visualizer.
Handles user control of the Visualizer .
private void run() {
        System.out.println("Welcome to the RubikTreeLang Visualizer.\n");
        displayValidCommands();
        Scanner in = new Scanner(System.in);
        while (true) {
            System.out.print("> ");
            String command = in.next();
            switch (command) {
                case "step":
                    int numSteps;
                    try {
                        numSteps = in.nextInt();
                    } catch (Exception e) {
                        System.out.println("Argument must be an integer.");
                        in.nextLine(); 
                        break;
                    }
                    if (numSteps < 0)
                        System.out.println("Argument must be non-negative.");
                    else
                        stepAtMost(numSteps);
                    in.nextLine();
                    break;
                case "stepuntil":
                    int end;
                    try {
                        end = in.nextInt();
                    } catch (Exception e) {
                        System.out.println("Argument must be an integer.");
                        in.nextLine();
                        break;
                    }
                    if (end > interp.getInstructions().length)
                        System.out.println(
                                "Specified end lies beyond end of program.");
                    else if (end < 0)
                        System.out.println("Argument must be non-negative.");
                    else
                        stepUntil(end);
                    in.nextLine();
                    break;
                case "run":
                    stepUntil(interp.getInstructions().length);
                    in.nextLine();
                    break;
                case "displaycube":
                    int id;
                    try {
                        id = in.nextInt();
                    } catch (Exception e) {
                        System.out.println("Argument must be an integer.");
                        in.nextLine();
                        break;
                    }
                    if (id >= interp.getTrie().getNumCubes())
                        System.out.println("Rubik's Cube with ID " + id
                                + " does not exist.");
                    else if (id < 0)
                        System.out.println("Argument must be non-negative.");
                    else {
                        RubiksCube cube = getCube(id);
                        if (cube == null)
                            System.out.println("Rubik's Cube with ID " + id
                                    + " does not exist.");
                        else
                            System.out.println(cube);
                    }
                    in.nextLine();
                    break;
                case "restart":
                    restart();
                    in.nextLine();
                    break;
                case "code":
                    displayCode();
                    in.nextLine();
                    break;
                case "exit":
                    return;
                default:
                    System.out.println("Invalid command.\n");
                    displayValidCommands();
                    in.nextLine();
            }
        }
    }
private void run ( ) { System . out . println ( "Welcome to the RubikTreeLang Visualizer.\n" ) ; displayValidCommands ( ) ; Scanner in = new Scanner ( System . in ) ; while ( true ) { System . out . print ( "> " ) ; String command = in . next ( ) ; switch ( command ) { case "step" : int numSteps ; try { numSteps = in . nextInt ( ) ; } catch ( Exception e ) { System . out . println ( "Argument must be an integer." ) ; in . nextLine ( ) ; break ; } if ( numSteps < 0 ) System . out . println ( "Argument must be non-negative." ) ; else stepAtMost ( numSteps ) ; in . nextLine ( ) ; break ; case "stepuntil" : int end ; try { end = in . nextInt ( ) ; } catch ( Exception e ) { System . out . println ( "Argument must be an integer." ) ; in . nextLine ( ) ; break ; } if ( end > interp . getInstructions ( ) . length ) System . out . println ( "Specified end lies beyond end of program." ) ; else if ( end < 0 ) System . out . println ( "Argument must be non-negative." ) ; else stepUntil ( end ) ; in . nextLine ( ) ; break ; case "run" : stepUntil ( interp . getInstructions ( ) . length ) ; in . nextLine ( ) ; break ; case "displaycube" : int id ; try { id = in . nextInt ( ) ; } catch ( Exception e ) { System . out . println ( "Argument must be an integer." ) ; in . nextLine ( ) ; break ; } if ( id >= interp . getTrie ( ) . getNumCubes ( ) ) System . out . println ( "Rubik's Cube with ID " + id + " does not exist." ) ; else if ( id < 0 ) System . out . println ( "Argument must be non-negative." ) ; else { RubiksCube cube = getCube ( id ) ; if ( cube == null ) System . out . println ( "Rubik's Cube with ID " + id + " does not exist." ) ; else System . out . println ( cube ) ; } in . nextLine ( ) ; break ; case "restart" : restart ( ) ; in . nextLine ( ) ; break ; case "code" : displayCode ( ) ; in . nextLine ( ) ; break ; case "exit" : return ; default : System . out . println ( "Invalid command.\n" ) ; displayValidCommands ( ) ; in . nextLine ( ) ; } } }
Handles user control of the Visualizer.
Handles user control of the Visualizer .
// consume extraneous arguments and \n