Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Java Programming Language with the ability to choose the 2 dimensional array's row size and column size Previous examples have not worked in the

In Java Programming Language with the ability to choose the 2 dimensional array's row size and column size Previous examples have not worked in the Q&A for me. Thank you.

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, 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 mouse move introduce a cat that may eat the mouse. The cat is a block of 4 maze locations forming a square. 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 size 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 four numbers. 1) The first is the number of times the mouse must start over before he finds a path from beginning to the end, 2) the second is the number of times he falls off the maze 3) the third is the number of times the cat catches the mouse, 4) the number of times the mouse lands on a previous position of the path. Then print the array to the screen showing the path that was successful and the last cat position. (HINT: use a two dimensional integer array, record the cat as 4 negative 1s in the maze. When you print out the maze replace a -1 with the char C.) Further in the program when you know the number of rows and columns from the client an array declaration would look like this.

int[][] maze = new int[rowNumber][columnNumber];

publicclassMazeLoopExample

{

privatestaticint[][] mouseArray;

staticintrowSize= 9;

staticintcolumnSize= 9;

publicstaticvoidmain(String[] args)

{

mouseArray= newint[rowSize][columnSize];

fillArray();

printArray();

}

privatestaticvoidprintArray()

{

intvalue;

for(introw= 0; row< rowSize; row++)

{

for(intcol= 0; col< columnSize; col++)

{

value= mouseArray[row][col];

if(value> 9)

System.out.print(" "+ value);

else

System.out.print(" "+ value);

}

System.out.println();

}

}

privatestaticvoidfillArray()

{

intnumber= 0;

for(introw= 0; row< rowSize; row++)

{

for(intcolumn= 0; column< columnSize; column++)

{

number++;

mouseArray[row][column]= number;

}

}

}

}

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

Step: 3

blur-text-image

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2014 Nancy France September 15 19 2014 Proceedings Part 3 Lnai 8726

Authors: Toon Calders ,Floriana Esposito ,Eyke Hullermeier ,Rosa Meo

2014th Edition

3662448440, 978-3662448441

More Books

Students also viewed these Databases questions

Question

Explain the importance of nonverbal messages.

Answered: 1 week ago

Question

Describe the advantages of effective listening.

Answered: 1 week ago

Question

Prepare an employment application.

Answered: 1 week ago