Question: IN JAVA PROGRAMMING LANGUAGE!!!!!! /* * This code was created by Clinton Rogers for the specific intent of being used by his students. * Derivative
IN JAVA PROGRAMMING LANGUAGE!!!!!!/* * This code was created by Clinton Rogers for the specific intent of being used by his students. * Derivative works based on this code may only be submitted to myCourses, and a copy local to the students * own computer. At no time should this code, derivative or otherwise, be shared with other students, * people, or posted online. */ import java.io.PrintWriter; import java.util.Random; public class MazeGenerator { private static Random rand = new Random(); private static void fillMatrix(char [][]matrix) { //Fill matrix with non-space characters /********************************************* * TODO FILL IN CODE HERE *********************************************/ } private static void burrowMaze(char [][] matrix, int x, int y) { /********************************************* * TODO FILL IN CODE HERE *********************************************/ } private static boolean hasWestNeighbor(char[][] matrix, int x, int y) { return (x-2)>=1 && matrix[x-2][y] != ' '; } private static boolean hasEastNeighbor(char[][] matrix, int x, int y) { return (x+2)
=1 && matrix[x][y-2] != ' '; } private static boolean hasSouthNeighbor(char[][] matrix, int x, int y) { return (y+2) CIS 181: Object-Oriented Programming II Project #1 Recursive Burrowing, Generate a Maze! (40 points total) Objectives To gain experience with using recursion by implementing the burrowMaze method. To gain experience with using static methods by implementing the MazeGenerator class To gain experience with implementing and using a 2d character array To gain experience using ranm number generation with an instance of the Random class. Description This is a solo project. You may not work with anyone else. You may get help from the TA's, mentors, and instructor Remember those placemats they give to kids at restaurants? Toss a couple crayons at you, and away you went. Inevitably they had a dinky maze on it that didn't take long to solve Well dinky mazes no more! In this project, you will complete the program that will create a maze ofany specified size (within reason, as this is a recursive solution and it will cause a stack overflow with really large maze sizes) How does it work? Imagine you are a worm placed on top of a new bucket of soil. Your job is to burrow through the dirt, but with the caveat that you will not cross over any tunnels you have already created. You move in mm increments in directions chosen at random. If you end up in a place where you can't burrow in any direction (or you cross over into another tunnel, you need to back up (backtracking!) and try a different direction Exercises . Download the following class source files MazeBurrowing.java MazeGenerator java 2. In Eclipse, create a new Java project called "Project 1", and import the above 2 files. 3. Compile and run the program. Make sure it works (although it won't do much beyond asking you the dimensions of the array) 4. The class MazeBurowing has been implemented for you. This is the main class 5. The class MazeGenerator needs to be implemented by you. Specifically the following can manually choose them when you go to print it). Scan or take pictures of the completed mazes. (10 points) methods need to be filled in .private statie void fill Matrix(char matrix) (5 points) 7. Submit your completed program and scans/pictures to myCourses Any work you create as a result of this project is the property of the University of Massachusetts Dartmouth. This documnt and any and all source code cannot be shared with anyone except University of Massachusetts Dartmouth faculty (including TA's), and in a private digital portfolio (public access online is prohibited) with the intention of applying to jobs and internships The purpose of this method is to fill the 2 dimensional aray with all one character. In the analogy above, you are filling the bucket with soil public static int burrowMaze(char0 matrix, intx, int y) (20 points) This method is the recursive method. matrix should already be filled with the character that you chose to fill it with in llMatrix o don't need to call it). a and y is the location your algorithm is currently at (in the analogy, it is where the worm currently is in the soil). At this point, your "worm" has to check to see if it can move in any direction. While the "wom" has "soi" neighbors, have it move randomly in that direction. This means burrowing through two spots by setting those cells to blank spaces and pass ing this method. When it can no longer make any moves (it has no neighbors), the method simply rctums. off this new location to a recursive call of To help with burowMaze, I have provided you with 5 methods. hasWest Neighbor 2 hasEastNeighbor 3 hasNor thNeighbor 4. hasSouthVeighbor You can use these methods to help you determine if there are neighbors and which neighbors it has. Again, neighbors are defined as a place you can burrow to, that will not burrow into an already existing tunnel. 5. Make sure you comment your program. This includes name, date, description, as well as general comments in the above mentioned methods (burrow Maze and fill Matrix).( points) 6. Test your program thoroughly with different size mazes. In MazeBurrowing.java, you will see the call to printMatrix, if you replace the textfile name with an empty string it will print the maze to the console. You can do this early on to quickly test your code. The down side is, after a certain size, the console will not accurately print out the maze (a limitation of the console). Once you are certain your maze works, print out 3 mazes of different sizes, and complete them with a pen or marker. Alternatively, you are granted permission to have a friend or family member complete the printed the mazes for you NOTE: your recursive algorithm does not need to make the "start" and "end" points, you * This code was created by Clinton Rogers for the specific intent of being used by his students. * Derivative works based on this code may only be submitted to myCourses, and a copy local to the students * own computer. At no time should this code, derivative or otherwise, be shared with other students, * people, or posted online. import java.util.Random; imp ort java.util.Scanner; public class MazeBurrowing public static void main(String[ ] args) // TODO Auto-generated method stub Scanner kb - new Scanner (System.in); System.out.println "How high would you like the maze to be? (Even numbers will be converted to odd) ") int y - kb.nextInt) System.out.println("How width would you like the maze to be? (Even numbers will be converted to odd)"); x -kb.nextInt( //Make sure the sizes are not negative y - Math.abs (y); x - Math.abs (x) //and make sure they are odd values if ( x%2 .. 0 ) x++i //create the grid char [][] grid-new char[x]yl MazeGenerator.generateMaze (grid,1,1); //Print the grid to a textfile or ""to print to screen MazeGenerator.printMatrix(grid, "Maze.txt") System.out.println("Done!"); CIS 181: Object-Oriented Programming II Project #1 Recursive Burrowing, Generate a Maze! (40 points total) Objectives To gain experience with using recursion by implementing the burrowMaze method. To gain experience with using static methods by implementing the MazeGenerator class To gain experience with implementing and using a 2d character array To gain experience using ranm number generation with an instance of the Random class. Description This is a solo project. You may not work with anyone else. You may get help from the TA's, mentors, and instructor Remember those placemats they give to kids at restaurants? Toss a couple crayons at you, and away you went. Inevitably they had a dinky maze on it that didn't take long to solve Well dinky mazes no more! In this project, you will complete the program that will create a maze ofany specified size (within reason, as this is a recursive solution and it will cause a stack overflow with really large maze sizes) How does it work? Imagine you are a worm placed on top of a new bucket of soil. Your job is to burrow through the dirt, but with the caveat that you will not cross over any tunnels you have already created. You move in mm increments in directions chosen at random. If you end up in a place where you can't burrow in any direction (or you cross over into another tunnel, you need to back up (backtracking!) and try a different direction Exercises . Download the following class source files MazeBurrowing.java MazeGenerator java 2. In Eclipse, create a new Java project called "Project 1", and import the above 2 files. 3. Compile and run the program. Make sure it works (although it won't do much beyond asking you the dimensions of the array) 4. The class MazeBurowing has been implemented for you. This is the main class 5. The class MazeGenerator needs to be implemented by you. Specifically the following can manually choose them when you go to print it). Scan or take pictures of the completed mazes. (10 points) methods need to be filled in .private statie void fill Matrix(char matrix) (5 points) 7. Submit your completed program and scans/pictures to myCourses Any work you create as a result of this project is the property of the University of Massachusetts Dartmouth. This documnt and any and all source code cannot be shared with anyone except University of Massachusetts Dartmouth faculty (including TA's), and in a private digital portfolio (public access online is prohibited) with the intention of applying to jobs and internships The purpose of this method is to fill the 2 dimensional aray with all one character. In the analogy above, you are filling the bucket with soil public static int burrowMaze(char0 matrix, intx, int y) (20 points) This method is the recursive method. matrix should already be filled with the character that you chose to fill it with in llMatrix o don't need to call it). a and y is the location your algorithm is currently at (in the analogy, it is where the worm currently is in the soil). At this point, your "worm" has to check to see if it can move in any direction. While the "wom" has "soi" neighbors, have it move randomly in that direction. This means burrowing through two spots by setting those cells to blank spaces and pass ing this method. When it can no longer make any moves (it has no neighbors), the method simply rctums. off this new location to a recursive call of To help with burowMaze, I have provided you with 5 methods. hasWest Neighbor 2 hasEastNeighbor 3 hasNor thNeighbor 4. hasSouthVeighbor You can use these methods to help you determine if there are neighbors and which neighbors it has. Again, neighbors are defined as a place you can burrow to, that will not burrow into an already existing tunnel. 5. Make sure you comment your program. This includes name, date, description, as well as general comments in the above mentioned methods (burrow Maze and fill Matrix).( points) 6. Test your program thoroughly with different size mazes. In MazeBurrowing.java, you will see the call to printMatrix, if you replace the textfile name with an empty string it will print the maze to the console. You can do this early on to quickly test your code. The down side is, after a certain size, the console will not accurately print out the maze (a limitation of the console). Once you are certain your maze works, print out 3 mazes of different sizes, and complete them with a pen or marker. Alternatively, you are granted permission to have a friend or family member complete the printed the mazes for you NOTE: your recursive algorithm does not need to make the "start" and "end" points, you * This code was created by Clinton Rogers for the specific intent of being used by his students. * Derivative works based on this code may only be submitted to myCourses, and a copy local to the students * own computer. At no time should this code, derivative or otherwise, be shared with other students, * people, or posted online. import java.util.Random; imp ort java.util.Scanner; public class MazeBurrowing public static void main(String[ ] args) // TODO Auto-generated method stub Scanner kb - new Scanner (System.in); System.out.println "How high would you like the maze to be? (Even numbers will be converted to odd) ") int y - kb.nextInt) System.out.println("How width would you like the maze to be? (Even numbers will be converted to odd)"); x -kb.nextInt( //Make sure the sizes are not negative y - Math.abs (y); x - Math.abs (x) //and make sure they are odd values if ( x%2 .. 0 ) x++i //create the grid char [][] grid-new char[x]yl MazeGenerator.generateMaze (grid,1,1); //Print the grid to a textfile or ""to print to screen MazeGenerator.printMatrix(grid, "Maze.txt") System.out.println("Done!")
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock



/* * This code was created by Clinton Rogers for the specific intent of being used by his students. * Derivative works based on this code may only be submitted to myCourses, and a copy local to the students * own computer. At no time should this code, derivative or otherwise, be shared with other students, * people, or posted online. */ import java.io.PrintWriter; import java.util.Random; public class MazeGenerator { private static Random rand = new Random(); private static void fillMatrix(char [][]matrix) { //Fill matrix with non-space characters /********************************************* * TODO FILL IN CODE HERE *********************************************/ } private static void burrowMaze(char [][] matrix, int x, int y) { /********************************************* * TODO FILL IN CODE HERE *********************************************/ } private static boolean hasWestNeighbor(char[][] matrix, int x, int y) { return (x-2)>=1 && matrix[x-2][y] != ' '; } private static boolean hasEastNeighbor(char[][] matrix, int x, int y) { return (x+2)