Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Entry level Java Programing Homework ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// MAZEBURROWING CLASS ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// import java.util.Random; import java.util.Scanner; public class MazeBurrowing { public static void main(String[] args) { // TODO

Entry level Java Programing Homework

image text in transcribed

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

MAZEBURROWING CLASS

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

import java.util.Random; import 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)"); int 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(y%2 == 0) y++; if(x%2 == 0) x++; //Create the grid char [][] grid = new char[x][y]; 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!"); } }

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

MAZEGENERATOR CLASS

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

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)  Exercises 1. 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. 5. The class MazeBurrowing has been implemented for you. This is the main class. The class MazeGenerator needs to be implemented by you. Specifically the following methods need to be filled in: private statie void fillMatrix( charmatrix) (5 points) The purpose of this method is to fill the 2 dimensional array with all one character. In the analogy above, you are filling the bucket with soil. public static int burrowMaze(char0matrix, 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 fillMatrix (you don 't need to call it)x 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 "worm" has "soil" neighbors, have it move randomly in that direction. This means burrowing through two spots by setting those cells to blank spaces and passing off this new location to a recursive call of this method. When it can no longer make any moves (it has no neighbors), the method simply returns. To help with burrowMaze, I have provided you with 5 methods. I. hasWestNeighbor 2. hasEastNeighbor 3. hasNorthNeighbor 4. hasSouthNeighbor 5. hasNoNeighbors 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 (burrowMaze and fillMatrix). (5 points)  Exercises 1. 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. 5. The class MazeBurrowing has been implemented for you. This is the main class. The class MazeGenerator needs to be implemented by you. Specifically the following methods need to be filled in: private statie void fillMatrix( charmatrix) (5 points) The purpose of this method is to fill the 2 dimensional array with all one character. In the analogy above, you are filling the bucket with soil. public static int burrowMaze(char0matrix, 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 fillMatrix (you don 't need to call it)x 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 "worm" has "soil" neighbors, have it move randomly in that direction. This means burrowing through two spots by setting those cells to blank spaces and passing off this new location to a recursive call of this method. When it can no longer make any moves (it has no neighbors), the method simply returns. To help with burrowMaze, I have provided you with 5 methods. I. hasWestNeighbor 2. hasEastNeighbor 3. hasNorthNeighbor 4. hasSouthNeighbor 5. hasNoNeighbors 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 (burrowMaze and fillMatrix). (5 points)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Mining Concepts And Techniques

Authors: Jiawei Han, Micheline Kamber, Jian Pei

3rd Edition

0123814790, 9780123814791

Students also viewed these Databases questions