Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

27. Marty the mouse is to navigate his way through a ten-foot by twenty-foot rec

ID: 672428 • Letter: 2

Question

27.  Marty the mouse is to navigate his way through a ten-foot by twenty-foot rectangular room whose floor is made of red and white one-foot square tiles. Marty hates red tiles and will only walk on white tiles. There is a piece of cheese at the exit. Write a program that outputs the row and column numbers of the white tiles Marty walks on as he finds his way to the cheese. Model the floor of the room using a two-dimensional array of integers, one element per tile. A value of 0 indicates a white tile, a value of 1 indicates a red tile. Assume the maze is navigable, and that the maze entrance location and exit location will be input by the user. (Hint: you will need two stacks for this application. One will store the path Marty has followed so he can backtrack if he encounters a dead end. A special location is pushed on this stack whenever Marty is at a tile from which he can proceed in more than one direction. As Marty steps onto a tile, if there are alternate tiles he could have stepped onto they are pushed onto the second stack.)

Explanation / Answer

Program:

package martyr;

import java.util.Stack;

public class tiles {

public tiles()

{

int[][] a = {{1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0},

{1,1,1,1,1,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0},

{0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1},

{0,0,0,0,0,1,1,1,1,1,0,1,0,1,0,1,0,1,0,1},

{ 0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1},

{0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1},

{ 0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0},

{0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,1,0},

{0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,1,0},

{0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,1,1,1}

};

}

public void maze(int a[][])

{

for(int i=0;i<10;i++)

{

for(int j=0;j<20;j++)

{

if(a[i][j]==1)

{

Stack c=new Stack();

{

}

}

}

}

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote