Question: I need help with changing a recursion assignment and need the maze.java and creating the TestMaze.java file. Three files are needed for this one is
I need help with changing a recursion assignment and need the maze.java and creating the TestMaze.java file. Three files are needed for this one is provided and a template for maze.java. I have provided the template and the provided menu.java code at the end.



Create a Maze object using the menu option as the maze type passed to the Maze constructor.
Call the Mazes traverseMaze method to traverse this maze.
Here is the Maze.java code:
// YOUR HEADER HERE!!! // public class Maze {
// Sample maze 1 final int MAZE1_ROWS = 12; final int MAZE1_COLS = 12; final int MAZE1_ENTERROW = 4; final int MAZE1_EXITROW = 8; final char[][] MAZE1 = { {'#','#','#','#','#','#','#','#','#','#','#','#'}, {'#','.','.','.','#','.','.','.','.','.','.','#'}, {'#','.','#','.','#','.','#','#','#','#','.','#'}, {'#','.','#','.','#','.','.','.','.','#','.','#'}, {'.','.','#','.','.','#','#','#','.','#','.','#'}, {'#','#','#','#','.','#','.','.','.','#','.','#'}, {'#','.','.','#','.','.','.','#','#','#','.','#'}, {'#','#','.','#','.','#','#','#','.','#','.','#'}, {'#','.','.','.','.','.','.','.','.','#','.','.'}, {'#','#','#','#','#','#','.','#','#','#','.','#'}, {'#','.','.','.','.','.','.','#','.','.','.','#'}, {'#','#','#','#','#','#','#','#','#','#','#','#'}};
// Sample maze 2 final int MAZE2_ROWS = 8; final int MAZE2_COLS = 12; final int MAZE2_ENTERROW = 6; final int MAZE2_EXITROW = 1; final char[][] MAZE2 = { {'#','#','#','#','#','#','#','#','#','#','#','#'}, {'#','.','.','.','#','.','.','.','#','#','.','.'}, {'#','.','#','.','.','.','#','.','.','.','.','#'}, {'#','.','#','#','#','#','.','#','.','#','.','#'}, {'#','.','.','.','#','#','.','.','.','.','.','#'}, {'#','#','#','.','#','#','#','#','.','#','.','#'}, {'.','.','.','.','.','.','.','.','.','.','#','#'}, {'#','#','#','#','#','#','#','#','#','#','#','#'}};
// Sample maze 3 final int MAZE3_ROWS = 9; final int MAZE3_COLS = 9; final int MAZE3_ENTERROW = 4; final int MAZE3_EXITROW = 3; final char[][] MAZE3 = { {'#','#','#','#','#','#','#','#','#'}, {'#','.','#','.','#','.','.','.','#'}, {'#','.','.','.','#','.','#','#','#'}, {'#','#','#','.','#','.','#','.','.'}, {'.','.','.','.','.','.','#','.','#'}, {'#','#','.','#','.','#','#','.','#'}, {'#','.','.','#','.','#','.','.','#'}, {'#','#','.','#','.','#','.','.','#'}, {'#','#','#','#','#','#','#','#','#'}};
// Sample maze 4 final int MAZE4_ROWS = 12; final int MAZE4_COLS = 12; final int MAZE4_ENTERROW = 2; final int MAZE4_EXITROW = 4; final char[][] MAZE4 = { {'#','#','#','#','#','#','#','#','#','#','#','#'}, {'#','.','.','.','#','.','.','.','.','.','.','#'}, {'.','.','#','.','#','.','#','#','#','#','.','#'}, {'#','#','#','.','#','.','.','.','.','#','.','#'}, {'#','.','.','.','.','#','#','#','.','#','.','.'}, {'#','#','#','#','.','#','.','#','.','#','.','#'}, {'#','.','.','#','.','#','.','#','.','#','.','#'}, {'#','#','.','#','.','#','.','#','.','#','.','#'}, {'#','.','.','.','.','.','.','.','.','#','.','#'}, {'#','#','#','#','#','#','.','#','#','#','.','#'}, {'#','.','.','.','.','.','.','#','.','.','.','#'}, {'#','#','#','#','#','#','#','#','#','#','#','#'}};
// Private data members for processing maze private char maze [][]; // the maze array to traverse private int rows; // the number of rows in this maze private int cols; // the number of columns in this maze private int enterRow; // the entry row for this maze; start column is 0 private int exitRow; // the exit row for this maze; end column is cols-1 private int steps; // number of steps in the solvable path
// METHODS HERE }
Here is the Menu.java file:
// Filename: Menu.java // Displays a list of menu options to the user (0th Array element is Quit and is displayed last) // Reads and validates user input import java.util.Scanner; import java.util.InputMismatchException;
public class Menu {
String options[]; // array of menu options for display as a menu Scanner input = new Scanner (System.in);
//----------------------------------------------------------------------------------------- // Method: Constructor // Takes an array of Strings and sets the array 'options' equal to the options provided public Menu (String [] opts) { options = new String [opts.length]; for (int x = 0; x
//----------------------------------------------------------------------------------------- // Method: runMenu // Displays the list of menu options // Prompts for, reads, validates and returns the user's choice public int runMenu () { int opt = -1; do {
System.out.println (" Choose from the following options: "); try { for (int x = 1; x
System.out.printf ("\t%d\t%s ", x, options[x]);
System.out.printf ("\t%d\t%s ",0 , options[0]); System.out.printf ("\tOption: "); opt = input.nextInt(); input.nextLine(); if (opt = options.length) System.out.println ("Invalid Menu Option - try again "); } // If the user enters a non-numeric value, catch and report the error // and allow the user to try again catch (InputMismatchException inputMismatchException){ System.out.println ("Invalid Menu Option - try again "); input.nextLine(); // clear the non-numeric value from the input } }while (opt = options.length); return opt; } }
Maze Program using Recursion Due: Wednesday, 8th March 2017, 11:59 p.m. Program 2: 70 points objectives: This programming exercise will provide experience using recursion to solve a moderately difficult programming problem. Program Description The user will be presented with the following menu: Select a Maze Choose from the following options: Maze 1 Maze 2 Maze 3 Maze 4 Quit After choosing an option, the program should attempt to find a path through the requested maze. The program will provide specific mazes for options 1-4. The program will display the initial maze including the maze dimensions and attempt to find a path through the maze. If a path is found, the message SOLVED will be displayed followed by a display of the maze with the valid path clearly marked. o The number of steps to move from the start point of the maze to the end point of the maze will also be shown If a path cannot be found, the message NOT SOLVED should be displayed. See the pages 4-7 of this assignment sheet for sample program output from this program. A sample maze: specifies a wall in the maze and I. specifies an open path The sample maze solved: 'O' indicates the path taken O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
