Task 3: Implement method setup in PE1 class. The description of what is wanted is given in the starter code. TASK 1 and 2 are done in class maze. Please use PE1 class. public class PE1 { MazedogMaze; /** * This method sets up the maze using the given input argument * @param maze is a maze that is used to construct the dogMaze */ publicvoidsetup(String[][]maze){ /* insert your code here to create the dogMaze * using the input argument. */ } /** * This method returns true if the number of * gates in dogMaze >= 2. * @return it returns true, if enough gate exists (at least 2), otherwise false. */ publicbooleanenoughGate(){ // insert your code here. Change the return value to fit your purpose. if() returntrue; } /** * This method finds a path from the entrance gate to * the exit gate. * @param row is the index of the row, where the entrance is. * @param column is the index of the column, where the entrance is. * @return it returns a string that contains the path from the start to the end. * The return value should have a pattern like this (i,j)(k,l),... * The first pair of the output must show the entrance given as the * input parameter (i.e. (row,column) * No whitespace is allowed in the output. */ publicStringfindPath(introw,intcolumn){ // insert your code here. Change the return value to fit your purpose. booleandone=false; if(valid(row,column)){ grid[row][column]=3; // cell has been tried if(row==grid.length-1&&column==grid[0].length-1) done=true; // maze is solved else{ done=findPath(row+1,column); // down if(!done) done=findPath(row,column+1); // right if(!done) done=findPath(row-1,column); // up if(!done) done=findPath(row,column-1); // left } if(done) // part of the final path grid[row][column]=7; } returndone; returnnull; } } /** * This class defines a maze using a 2D array. * To complete the code, you should not change the method * signatures (header). * */ class Maze{ privateString[][]maze; /** * This constructor makes the maze. * @param maze is a 2D array that contains information * on how each cell of the array looks like. */ publicMaze(String[][]maze){ /*complete the constructor so that the maze is * a deep copy of the input parameter. */ String[][]mazeArray={ {1100,1000,1010,1010,1001,1100,1000,1001,1100,1001}, {0101,0110,1010,1001,0101,0101,0111,0101,0101,0101}, {0101,1110,1001,0101,0111,0110,1001,0101,0111,0101}, {0101,1100,0011,0101,1100,1010,0011,0101,1100,0010}, {0100,0011,1100,0011,0101,1100,1001,0101,0110,1001}, {0100,1001,0100,1001,0110,0011,0101,0110,1010,0011}, {0101,0101,0101,0100,1000,1000,0011,1110,1010,1001}, {0101,0111,0101,0101,0111,0100,1000,1000,1011,0101}, {0111,1100,0011,0110,1001,0101,0111,0110,1010,0011}, {1001,0111,1100,1010,0011,0110,1010,1010,1010,1001}, {0110,1000,0001,1100,1010,1001,1100,1001,1101,0101}, {1101,0101,0101,0110,1011,0110,0011,0101,0101,0101}, {0110,0001,0110,1001,1100,1001,1100,0011,0110,0001}, {1101,0110,1001,0110,0011,0110,0011,1100,1010,0001}, {0110,1010,0011,1110,1010,1010,1010,0011,1110,0011}}; this.maze=newString[maze.length][]; for(inti=0;i
Task 3:
Implement method setup in PE1 class. The description of what is wanted is given in the starter code.
TASK 1 and 2 are done in class maze. Please use PE1 class.
public class PE1 {
MazedogMaze;
/**
* This method sets up the maze using the given input argument
* @param maze is a maze that is used to construct the dogMaze
*/
publicvoidsetup(String[][]maze){
/* insert your code here to create the dogMaze
* using the input argument.
*/
}
/**
* This method returns true if the number of
* gates in dogMaze >= 2.
* @return it returns true, if enough gate exists (at least 2), otherwise false.
*/
publicbooleanenoughGate(){
// insert your code here. Change the return value to fit your purpose.
if()
returntrue;
}
/**
* This method finds a path from the entrance gate to
* the exit gate.
* @param row is the index of the row, where the entrance is.
* @param column is the index of the column, where the entrance is.
* @return it returns a string that contains the path from the start to the end.
* The return value should have a pattern like this (i,j)(k,l),...
* The first pair of the output must show the entrance given as the
* input parameter (i.e. (row,column)
* No whitespace is allowed in the output.
*/
publicStringfindPath(introw,intcolumn){
// insert your code here. Change the return value to fit your purpose.
booleandone=false;
if(valid(row,column)){
grid[row][column]=3; // cell has been tried
if(row==grid.length-1&&column==grid[0].length-1)
done=true; // maze is solved
else{
done=findPath(row+1,column); // down
if(!done)
done=findPath(row,column+1); // right
if(!done)
done=findPath(row-1,column); // up
if(!done)
done=findPath(row,column-1); // left
}
if(done) // part of the final path
grid[row][column]=7;
}
returndone;
returnnull;
}
}
/**
* This class defines a <code> maze </code> using a 2D array.
* To complete the code, you should not change the method
* signatures (header).
*
*/
class Maze{
privateString[][]maze;
/**
* This constructor makes the maze.
* @param maze is a 2D array that contains information
* on how each cell of the array looks like.
*/
publicMaze(String[][]maze){
/*complete the constructor so that the maze is
* a deep copy of the input parameter.
*/
String[][]mazeArray={
{1100,1000,1010,1010,1001,1100,1000,1001,1100,1001},
{0101,0110,1010,1001,0101,0101,0111,0101,0101,0101},
{0101,1110,1001,0101,0111,0110,1001,0101,0111,0101},
{0101,1100,0011,0101,1100,1010,0011,0101,1100,0010},
{0100,0011,1100,0011,0101,1100,1001,0101,0110,1001},
{0100,1001,0100,1001,0110,0011,0101,0110,1010,0011},
{0101,0101,0101,0100,1000,1000,0011,1110,1010,1001},
{0101,0111,0101,0101,0111,0100,1000,1000,1011,0101},
{0111,1100,0011,0110,1001,0101,0111,0110,1010,0011},
{1001,0111,1100,1010,0011,0110,1010,1010,1010,1001},
{0110,1000,0001,1100,1010,1001,1100,1001,1101,0101},
{1101,0101,0101,0110,1011,0110,0011,0101,0101,0101},
{0110,0001,0110,1001,1100,1001,1100,0011,0110,0001},
{1101,0110,1001,0110,0011,0110,0011,1100,1010,0001},
{0110,1010,0011,1110,1010,1010,1010,0011,1110,0011}};
this.maze=newString[maze.length][];
for(inti=0;i<maze.length;i++){
this.maze[i]=newString[maze[i].length];
for(intj=0;j<maze[i].length;j++){
this.maze[i][j]=maze[i][j];
}
}
}
publicMaze(){
// TODO Auto-generated constructor stub
//this.maze = new String[0][];
}
/**
* This accessor (getter) method returns a 2D array that
* represents the maze
* @return it returns a reference to the maze
*/
publicString[][]getMaze(){
/* complete this method providing that a clone of
* the maze should be returned.
* you may want to change the return value to fit your purpose.
*/
String[][]maze=newString[this.maze.length][];
for(inti=0;i<maze.length;i++){
maze[i]=newString[this.maze[i].length];
for(intj=0;j<maze[i].length;j++){
maze[i][j]=this.maze[i][j];
}
}
returnmaze;
}
@Override
publicStringtoString(){
//insert your code here. Change the return value to fit your purpose.
Stringoutput="";
for(inti=0;i<maze.length;i++){
output+="[";
for(intj=0;j<maze[i].length;j++){
if(j!=0)
output+=" ";
output+=maze[i][j];
}
output+="]";
if(i!=maze.length-1)
output+="\n";
}
}
}// end of class Maze
Step by step
Solved in 2 steps