Question: Create a path for a mouse to travel in a maze. Use a 2 dimensional array and start the mouse in location array[0][0]. The mouse

Create a path for a mouse to travel in a maze. Use a 2 dimensional array and start the mouse in location array[0][0]. The mouse must find its way to the opposite corner. Repeatedly get a random number representing one of 8 possible moves. A legal move is one that moves forward, and does not run off the edge of the maze and does not land on a previous move. If the move is illegal the poor mouse must starts over with location [0][0]. Going forward is defined as the sum of the two array indexes either increasing or staying the same. With each safe move made by the mouse create a cat. the random number generator generates a location that serves as the upper left corner location of the cat. The random number is dependent on the sixth and shape of the maze when the maze is first created. If the cat catches the mouse the mouse must begin again. Think through the operations I have described and make those operations methods that can be called in order to accomplish the cat aspect of the problem. I used four small methods to implement the cat part of the project. Allow the mouse to repeatedly run the maze and choose the size of the two-dimensional maze. The output consists of three numbers. The first is the number of times the mouse must start over before he finds a path from beginning to the end, the second is the number of times he falls off the maze and the third is the number of times the cat catches the mouse. Then print the array to the screen showing the path that was successful and the last cat position. (HINT: use a two-dimension integer array, record the cat as 4 negative ones in the maze. When you print the maze replace a -1 with the char C.) Using the DecimalFormat class found in Appendix 4 add commas to the output. Example: 1,564,678.

Also the given code for creating two dimensional array: int[ ][ ] table = new int[7][5];

Output should look like this:

This program finds a path for a mouse from one corner to another in a two-dimensional maze.

Please enter the size of the maze. How many rows would you like?

10

How many columns would you like?

12

It took 1,483,505 attempts to find a path.

The cat got the mouse 41,672 times.

The mouse fell off the maze 437,806 times.

1 0 0 0 0 0 0 0 0 0 0 0

0 2 3 0 0 0 0 0 0 0 0 0

0 0 0 4 5 0 0 0 0 0 0 0

0 0 0 0 0 6 0 0 0 0 0 0

0 0 0 0 0 7 0 0 0 0 0 0

0 0 0 0 0 8 0 0 0 0 0 0

0 0 C C 0 0 9 0 0 0 0 0

0 0 C C 0 0 0 10 12 13 14 0

0 0 0 0 0 0 0 11 0 0 15 0

0 0 0 0 0 0 0 0 0 0 0 16

I saw some answer with C++ codes. Please use Java codes for this one. Thanks

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!