SlideShare a Scribd company logo
1 of 10
Download to read offline
Requirements :
Use Java
Do Not Use Recursion
Do Not Use Array List Use The Methods Provided
Use What Is Provided Only Make And Use The Helper Methods The Instructions Say You Can
Only Provide The Answer Code
Thank You ! I'm Having The Hardest Time Understanding This
Maze Solving with Stacks
Consider a maze made up of rectangular array of squares, such as the following one:
X X X X X X X X X X X X X
X X X X X X
X X X X X
X X X X X X X X
X X X X X
X X X X X X X
X X X X X X X X X X X X X
Figure 1--- A sample maze
The X blocks represent a blocked square and form the walls of the maze. Let us consider mazes
that
have only one entrance and one exit, as in our example. Beginning at the entrance at the top left
side of
the maze, find a path to the exit at the bottom right side. You can move only up, down, left, or
right.
Square is either clear or blocked by an X character.
Let a two-dimensional array represent the maze. Use a stack data structure to find a path through
the
maze. Some mazes might have more than one successful path, while others might have no path.
Hints:
The primary consideration is that if you reach a dead end, you need to be able to backtrack
along the path to the point where you can try a different path. The stack data structure makes it
possible to store the current path and backtrack if necessary. Every clear position visited in the
current path is pushed to the stack and if a dead end is reached, the previous position is popped
from the stack to backtrack. You need to have a loop that begins with the start position and
pushes it into the stack then moves to a neighboring cell until either the goal position is reached,
or the stack becomes empty.
Make sure to mark each clear array cell you move to as visited to avoid checking it again and
getting stuck in an infinite loop. For example, each array cell can have three different values: X
for blocked, V for visited, and for clear.
A dead end is an array cell whose all neighbors are either blocked or already visited.
Maze Solving with Stacks
CSC 385
What you need to do:
There are four files you should pay attention to:
Position.java: a class to store the position of an array cell. It has two attributes: row and
column along with their accessor and mutator methods. It also has an equals method that
checks for equality of two Position objects.
Maze.java: a class to store a maze. It has 3 attributes: a two-dimensional character array which
represents the maze, a Position object to represent the start location, and another Position
object to represent the stop location.
MazeSolver: This class contains one static method, solve. It accepts a maze and returns an
array of Positions that is used to traverse the maze if the maze is solvable. If the maze is not
solvable then an empty array is returned.
o Keep in mind that stacks store objects in reverse order so be sure to return the position
array in the correct order.
Tester: a sample driver class which calls the traverse method on a maze in either the
SolvableMaze, UnsolvableMaze, or HugeSolvableMaze files. These should be at the root of the
project folder.
You only need to implement the solve method in the MazeSolver.java class. This method
receives
the maze to solve as a parameter and returns an array of Position objects which stores a solution
to
the maze if such solution exists; otherwise, it returns an empty array.
Note: There might be more than one possible solution to a maze, depending on the ordering in
which the neighboring cells are visited at each location. You can do whatever order you want if
the
maze is solved. For instance,
First move left, if the left neighbor is not clear, then move right, if the right neighbor is not clear,
then move up, if it is not clear, then move down.
You may create any additional helper methods to aid you. For instance, you may make a method
to convert the stack to a necessary array. Just remember, when you grab the information from a
stack you are getting in the reverse order you push them.
You must solve the problem using a Stack. You may use the built-in stack library but use of any
other data structure is prohibited apart from constructing the final Position array result.
Recursion is also not allowed.
What you need to turn in:
You need to submit the MazeSolver.java file containing your implementation of the solve
method.
Maze Solving with Stacks
CSC 385
Rubric
Stack is utilized 75
Iterative solution 5
Returns correct solutions to solvable mazes 10
Returns correct solutions to unsolvable mazes 10
Additional Notes and Helpful Hints
First hint I have is to not be afraid of creating additional variables to store information. For
instance, you
must move up, down, left, and right (or north, south, west, and east). Creating Position objects to
represent these movements is perfectly acceptable. You will also want to create an object that is
the
walker of the maze. This walker keeps the current position in the maze.
Other than push, pop, and peek on the Stack class, isEmpty is also a useful method.
The maze class contains a bunch of methods that is meant to help you. Read what the methods
do and
decide which ones you want to use for your solution. Read the code given to you FIRST before
starting
to write your code so you can utilize it. It is there to make your life easier, not harder.
Try to translate what you want to do in terms of the stack operations. For instance, if you find
yourself
at a dead end then you want to move back to a previous position. This means you will need to
first pop
the top position, which contains the spot located at the dead end, then peek to see where you
need to
be.
Your stack should be declared and initialized as such:
Stack __Give it a name__ = new Stack();
where you can name it whatever you want.
Moving in a two-dimensional array requires the following math:
Move up (North) Row + 1
Move down (South) Row - 1
Move left (West) Column - 1
Move right (East) Column + 1
The Provided Code : Plus The Method I Need Solved !
Position.java
public class Position {
/***************************
* Attributes
****************************/
private int row;
private int column;
/***************************
* Constructor
*
* @param row
* @param column
***************************/
public Position(int row, int column) {
this.row = row;
this.column = column;
}
/**************************
* Checks two positions for equality. Two positions are equal if the have the
* same row and column numbers.
*************************/
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (!(obj instanceof Position)) {
return false;
}
Position otherPosition = (Position) obj;
return (otherPosition.row == row && otherPosition.column == column);
}
public String toString() {
return "row:" + row + " column:" + column;
}
/**************************
* Getter and Setter methods
*
* @return
*/
public int getRow() {
return row;
}
public int getColumn() {
return column;
}
}
Maze.java
public class Maze {
/**
* Two dimensional array to represent a maze
*/
private final char[][] maze;
private final Position start, end;
/**
* Constructor initializing the maze array
*
* @param maze
*/
public Maze(char[][] maze, Position start, Position end) {
this.maze = maze;
if (validPosition(start)) {
this.start = start;
} else {
throw new PositionNotValidException("The start position is valid for the maze: " + start);
}
if (validPosition(end)) {
this.end = end;
} else {
throw new PositionNotValidException("The stop position is valid for the maze: " + end);
}
}
/**
* Returns the start position object.
*
* @return The start position.
*/
public Position getStart() {
return start;
}
/**
* Returns the stop position object.
*
* @return
*/
public Position getEnd() {
return end;
}
/**
* Returns the number of rows the maze has.
*
* @return The number of rows.
*/
public int numRows() {
return maze.length;
}
/**
* Returns the number of columns the row of the maze has.
*
* @param row The row to get the length of.
* @return The length of the row in the maze.
*/
public int numCols(int row) {
return maze[row].length;
}
/**
* Tests if row and column are valid within the two dimensional array. Will
* return true iff row is between 0 and maze.length-1 and column is between 0
* and maze[row].length - 1.
*
* @param row Represents the array to retrieve from maze.
* @param col Represents the character to retrieve from the array at maze[row].
* @return True iff the row and column are valid indices of maze otherwise
* false.
*/
public boolean validPosition(int row, int col) {
if (row >= 0 && row < maze.length) {
if (col >= 0 && col < maze[row].length) {
return true;
}
}
return false;
}
/**
* Tests if the row and column stored in pos are valid. Drops to the
* validPosition(int row, int col) method.
*
* @param pos The position to test.
* @return True iff pos is valid inside the maze otherwise false.
*/
public boolean validPosition(Position pos) {
return validPosition(pos.getRow(), pos.getColumn());
}
/**
* Returns the character at pos.
*
* @param pos The position to retrieve the character at.
* @return The character at maze[pos.row][pos.column]
* @throws PositionNotValidException if the position is now within the maze.
*/
public char getAt(Position pos) {
if (validPosition(pos)) {
return maze[pos.getRow()][pos.getColumn()];
} else {
String msg = String.format("The position given is not valid: %s", pos.toString());
throw new PositionNotValidException(msg);
}
}
/**
* Retrieves the character at maze[row][column].
*
* @param row The row to retrieve the character from.
* @param column The column to retrieve the character from.
* @return The character at position row, column
* @throws PositionNotValidException if the row or column are not within bounds.
*/
public char getAt(int row, int column) {
if (validPosition(row, column)) {
return maze[row][column];
} else {
String msg = String.format("The row and column given is not valid: row %d col %d", row,
column);
throw new PositionNotValidException(msg);
}
}
/**
* Sets a character at a specified position.
*
* @param pos The position to set the character at.
* @param c The character to set at position.
* @throws PositionNotValidException if the position passed in is not valid
* within the maze.
*/
public void setAt(Position pos, char c) {
if (validPosition(pos)) {
setAt(pos.getRow(), pos.getColumn(), c);
} else {
String msg = String.format("The position given is not valid: %s", pos.toString());
throw new PositionNotValidException(msg);
}
}
/**
* Sets a character at a specified row and column.
*
* @param pos The position to set the character at.
* @param c The character to set at position.
* @throws PositionNotValidException if the position passed in is not valid
* within the maze.
*/
public void setAt(int row, int column, char c) {
if (validPosition(row, column)) {
maze[row][column] = c;
} else {
String msg = String.format("The row and column given is not valid: row %d col %d", row,
column);
throw new PositionNotValidException(msg);
}
}
/*** METHODS NOT NEEDED TO HELP SOLVE THE PROBLEM. ****/
/*** YOU DO NOT NEED TO USE THESE METHODS AS THEY ****/
/*** ARE USED IN THE MAIN CLASS. ****/
public Maze clone() {
char clone[][] = new char[maze.length][];
for (int r = 0; r < maze.length; r++) {
clone[r] = new char[maze[r].length];
for (int c = 0; c < maze[r].length; c++) {
clone[r][c] = maze[r][c];
}
}
return new Maze(clone, start, end);
}
public String toString() {
StringBuffer sb = new StringBuffer();
for (int r = 0; r < maze.length; r++) {
sb.append(maze[r]);
sb.append("n");
}
return sb.toString();
}
}
MazeSolver.java - ONE THAT I NEED A HELP WITH!!
import java.util.Stack;
/**
* Notes:
*
* The start and end position are contained within the maze object. Use the
* getStart() and getEnd() methods.
*
*/
public class MazeSolver {
/**
* You need to implement this method
*
* @param maze: The maze to be solved.
* @return An array of Position which stores a solution to the maze. If a
* solution is not found a null value should be returned.
*/
public static Position[] solve(Maze maze) {
return null;
}
}

More Related Content

Similar to Requirements Use JavaDo Not Use RecursionDo Not Use Array Lis.pdf

RubyMiniGuide-v1.0_0
RubyMiniGuide-v1.0_0RubyMiniGuide-v1.0_0
RubyMiniGuide-v1.0_0tutorialsruby
 
RubyMiniGuide-v1.0_0
RubyMiniGuide-v1.0_0RubyMiniGuide-v1.0_0
RubyMiniGuide-v1.0_0tutorialsruby
 
Please make the complete program, Distinguish between header files a.pdf
Please make the complete program, Distinguish between header files a.pdfPlease make the complete program, Distinguish between header files a.pdf
Please make the complete program, Distinguish between header files a.pdfSALES97
 
JAVA CONCEPTS AND PRACTICES
JAVA CONCEPTS AND PRACTICESJAVA CONCEPTS AND PRACTICES
JAVA CONCEPTS AND PRACTICESNikunj Parekh
 
Sequence and Traverse - Part 2
Sequence and Traverse - Part 2Sequence and Traverse - Part 2
Sequence and Traverse - Part 2Philip Schwarz
 
Back tracking and branch and bound class 20
Back tracking and branch and bound class 20Back tracking and branch and bound class 20
Back tracking and branch and bound class 20Kumar
 
Branch and bound
Branch and boundBranch and bound
Branch and boundAcad
 
Java Question help needed In the program Fill the Add statements.pdf
Java Question  help needed In the program Fill the Add statements.pdfJava Question  help needed In the program Fill the Add statements.pdf
Java Question help needed In the program Fill the Add statements.pdfkamdinrossihoungma74
 
Read carefully and follow exactly Java You are to write a Breakou.pdf
Read carefully and follow exactly Java You are to write a Breakou.pdfRead carefully and follow exactly Java You are to write a Breakou.pdf
Read carefully and follow exactly Java You are to write a Breakou.pdfrupeshmehta151
 
Please Please Please Read the instructions and do everything li.docx
Please Please Please Read the instructions and do everything li.docxPlease Please Please Read the instructions and do everything li.docx
Please Please Please Read the instructions and do everything li.docxtienmixon
 
(Radhika) presentation on chapter 2 ai
(Radhika) presentation on chapter 2 ai(Radhika) presentation on chapter 2 ai
(Radhika) presentation on chapter 2 aiRadhika Srinivasan
 
module5_backtrackingnbranchnbound_2022.pdf
module5_backtrackingnbranchnbound_2022.pdfmodule5_backtrackingnbranchnbound_2022.pdf
module5_backtrackingnbranchnbound_2022.pdfShiwani Gupta
 
Backtrack search-algorithm
Backtrack search-algorithmBacktrack search-algorithm
Backtrack search-algorithmRuchika Sinha
 

Similar to Requirements Use JavaDo Not Use RecursionDo Not Use Array Lis.pdf (20)

RubyMiniGuide-v1.0_0
RubyMiniGuide-v1.0_0RubyMiniGuide-v1.0_0
RubyMiniGuide-v1.0_0
 
RubyMiniGuide-v1.0_0
RubyMiniGuide-v1.0_0RubyMiniGuide-v1.0_0
RubyMiniGuide-v1.0_0
 
CAP615-Unit1.pptx
CAP615-Unit1.pptxCAP615-Unit1.pptx
CAP615-Unit1.pptx
 
Please make the complete program, Distinguish between header files a.pdf
Please make the complete program, Distinguish between header files a.pdfPlease make the complete program, Distinguish between header files a.pdf
Please make the complete program, Distinguish between header files a.pdf
 
JAVA CONCEPTS AND PRACTICES
JAVA CONCEPTS AND PRACTICESJAVA CONCEPTS AND PRACTICES
JAVA CONCEPTS AND PRACTICES
 
Jist of Java
Jist of JavaJist of Java
Jist of Java
 
Sequence and Traverse - Part 2
Sequence and Traverse - Part 2Sequence and Traverse - Part 2
Sequence and Traverse - Part 2
 
Back tracking and branch and bound class 20
Back tracking and branch and bound class 20Back tracking and branch and bound class 20
Back tracking and branch and bound class 20
 
Branch and bound
Branch and boundBranch and bound
Branch and bound
 
Java Question help needed In the program Fill the Add statements.pdf
Java Question  help needed In the program Fill the Add statements.pdfJava Question  help needed In the program Fill the Add statements.pdf
Java Question help needed In the program Fill the Add statements.pdf
 
Problem space
Problem spaceProblem space
Problem space
 
Problem space
Problem spaceProblem space
Problem space
 
Problem space
Problem spaceProblem space
Problem space
 
7 stacksqueues
7 stacksqueues7 stacksqueues
7 stacksqueues
 
Read carefully and follow exactly Java You are to write a Breakou.pdf
Read carefully and follow exactly Java You are to write a Breakou.pdfRead carefully and follow exactly Java You are to write a Breakou.pdf
Read carefully and follow exactly Java You are to write a Breakou.pdf
 
Please Please Please Read the instructions and do everything li.docx
Please Please Please Read the instructions and do everything li.docxPlease Please Please Read the instructions and do everything li.docx
Please Please Please Read the instructions and do everything li.docx
 
(Radhika) presentation on chapter 2 ai
(Radhika) presentation on chapter 2 ai(Radhika) presentation on chapter 2 ai
(Radhika) presentation on chapter 2 ai
 
module5_backtrackingnbranchnbound_2022.pdf
module5_backtrackingnbranchnbound_2022.pdfmodule5_backtrackingnbranchnbound_2022.pdf
module5_backtrackingnbranchnbound_2022.pdf
 
Backtrack search-algorithm
Backtrack search-algorithmBacktrack search-algorithm
Backtrack search-algorithm
 
Backtracking
BacktrackingBacktracking
Backtracking
 

More from alphaagenciesindia

Researchers studying the STAR data report anecdotal evidence that sc.pdf
Researchers studying the STAR data report anecdotal evidence that sc.pdfResearchers studying the STAR data report anecdotal evidence that sc.pdf
Researchers studying the STAR data report anecdotal evidence that sc.pdfalphaagenciesindia
 
Research results suggest a relationship between the TV viewing habit.pdf
Research results suggest a relationship between the TV viewing habit.pdfResearch results suggest a relationship between the TV viewing habit.pdf
Research results suggest a relationship between the TV viewing habit.pdfalphaagenciesindia
 
Research done by doctors show that individuals with Kreuzfeld-Jacob .pdf
Research done by doctors show that individuals with Kreuzfeld-Jacob .pdfResearch done by doctors show that individuals with Kreuzfeld-Jacob .pdf
Research done by doctors show that individuals with Kreuzfeld-Jacob .pdfalphaagenciesindia
 
Research and describe TWO diseases - The cardiovascular disease .pdf
Research and describe TWO diseases - The cardiovascular disease .pdfResearch and describe TWO diseases - The cardiovascular disease .pdf
Research and describe TWO diseases - The cardiovascular disease .pdfalphaagenciesindia
 
Required The City of Mississauga Goes Digital The City of Mississ.pdf
Required The City of Mississauga Goes Digital The City of Mississ.pdfRequired The City of Mississauga Goes Digital The City of Mississ.pdf
Required The City of Mississauga Goes Digital The City of Mississ.pdfalphaagenciesindia
 
Required1-a. Determine Mahomess pension expense for 2024.1-b, .pdf
Required1-a. Determine Mahomess pension expense for 2024.1-b, .pdfRequired1-a. Determine Mahomess pension expense for 2024.1-b, .pdf
Required1-a. Determine Mahomess pension expense for 2024.1-b, .pdfalphaagenciesindia
 
Relaciona cada �poca con sus caracter�sticas definitorias. Per�od.pdf
Relaciona cada �poca con sus caracter�sticas definitorias.  Per�od.pdfRelaciona cada �poca con sus caracter�sticas definitorias.  Per�od.pdf
Relaciona cada �poca con sus caracter�sticas definitorias. Per�od.pdfalphaagenciesindia
 
Regarding the management of R&D teams after Vandeputte�s diversifica.pdf
Regarding the management of R&D teams after Vandeputte�s diversifica.pdfRegarding the management of R&D teams after Vandeputte�s diversifica.pdf
Regarding the management of R&D teams after Vandeputte�s diversifica.pdfalphaagenciesindia
 
Reflect on your current workplace where you currently interact with .pdf
Reflect on your current workplace where you currently interact with .pdfReflect on your current workplace where you currently interact with .pdf
Reflect on your current workplace where you currently interact with .pdfalphaagenciesindia
 
Reflexiona sobre un cambio profesional importante que hayas experime.pdf
Reflexiona sobre un cambio profesional importante que hayas experime.pdfReflexiona sobre un cambio profesional importante que hayas experime.pdf
Reflexiona sobre un cambio profesional importante que hayas experime.pdfalphaagenciesindia
 
ReinforcementR-4.3 Viruses that perform no explicit malicious beha.pdf
ReinforcementR-4.3 Viruses that perform no explicit malicious beha.pdfReinforcementR-4.3 Viruses that perform no explicit malicious beha.pdf
ReinforcementR-4.3 Viruses that perform no explicit malicious beha.pdfalphaagenciesindia
 
Required 1. prepare the Income Statement for the year ended Decembe.pdf
Required 1. prepare the Income Statement for the year ended Decembe.pdfRequired 1. prepare the Income Statement for the year ended Decembe.pdf
Required 1. prepare the Income Statement for the year ended Decembe.pdfalphaagenciesindia
 
Required Designate where each of the following events would be pre.pdf
Required  Designate where each of the following events would be pre.pdfRequired  Designate where each of the following events would be pre.pdf
Required Designate where each of the following events would be pre.pdfalphaagenciesindia
 
Routes of Administration The nurse is teaching clients with inflamma.pdf
Routes of Administration The nurse is teaching clients with inflamma.pdfRoutes of Administration The nurse is teaching clients with inflamma.pdf
Routes of Administration The nurse is teaching clients with inflamma.pdfalphaagenciesindia
 
Renzo es un l�der entusiasta que cree en sus ideas. Renzo se detiene.pdf
Renzo es un l�der entusiasta que cree en sus ideas. Renzo se detiene.pdfRenzo es un l�der entusiasta que cree en sus ideas. Renzo se detiene.pdf
Renzo es un l�der entusiasta que cree en sus ideas. Renzo se detiene.pdfalphaagenciesindia
 
Romance en la oficina buscando respuestas a tientasDescripci�n de.pdf
Romance en la oficina buscando respuestas a tientasDescripci�n de.pdfRomance en la oficina buscando respuestas a tientasDescripci�n de.pdf
Romance en la oficina buscando respuestas a tientasDescripci�n de.pdfalphaagenciesindia
 
ROBOTICS Currently, roboticists and AI researchers are still strug.pdf
ROBOTICS Currently, roboticists and AI researchers are still strug.pdfROBOTICS Currently, roboticists and AI researchers are still strug.pdf
ROBOTICS Currently, roboticists and AI researchers are still strug.pdfalphaagenciesindia
 
Roberts Rules of Order refer toA.procedural guidelines on the corre.pdf
Roberts Rules of Order refer toA.procedural guidelines on the corre.pdfRoberts Rules of Order refer toA.procedural guidelines on the corre.pdf
Roberts Rules of Order refer toA.procedural guidelines on the corre.pdfalphaagenciesindia
 
RKO-Stanley v. GrazianoEagen, J.On April 30, 1970, RKO-Stanley W.pdf
RKO-Stanley v. GrazianoEagen, J.On April 30, 1970, RKO-Stanley W.pdfRKO-Stanley v. GrazianoEagen, J.On April 30, 1970, RKO-Stanley W.pdf
RKO-Stanley v. GrazianoEagen, J.On April 30, 1970, RKO-Stanley W.pdfalphaagenciesindia
 
Robert and Charles are trying to decide what form of business to for.pdf
Robert and Charles are trying to decide what form of business to for.pdfRobert and Charles are trying to decide what form of business to for.pdf
Robert and Charles are trying to decide what form of business to for.pdfalphaagenciesindia
 

More from alphaagenciesindia (20)

Researchers studying the STAR data report anecdotal evidence that sc.pdf
Researchers studying the STAR data report anecdotal evidence that sc.pdfResearchers studying the STAR data report anecdotal evidence that sc.pdf
Researchers studying the STAR data report anecdotal evidence that sc.pdf
 
Research results suggest a relationship between the TV viewing habit.pdf
Research results suggest a relationship between the TV viewing habit.pdfResearch results suggest a relationship between the TV viewing habit.pdf
Research results suggest a relationship between the TV viewing habit.pdf
 
Research done by doctors show that individuals with Kreuzfeld-Jacob .pdf
Research done by doctors show that individuals with Kreuzfeld-Jacob .pdfResearch done by doctors show that individuals with Kreuzfeld-Jacob .pdf
Research done by doctors show that individuals with Kreuzfeld-Jacob .pdf
 
Research and describe TWO diseases - The cardiovascular disease .pdf
Research and describe TWO diseases - The cardiovascular disease .pdfResearch and describe TWO diseases - The cardiovascular disease .pdf
Research and describe TWO diseases - The cardiovascular disease .pdf
 
Required The City of Mississauga Goes Digital The City of Mississ.pdf
Required The City of Mississauga Goes Digital The City of Mississ.pdfRequired The City of Mississauga Goes Digital The City of Mississ.pdf
Required The City of Mississauga Goes Digital The City of Mississ.pdf
 
Required1-a. Determine Mahomess pension expense for 2024.1-b, .pdf
Required1-a. Determine Mahomess pension expense for 2024.1-b, .pdfRequired1-a. Determine Mahomess pension expense for 2024.1-b, .pdf
Required1-a. Determine Mahomess pension expense for 2024.1-b, .pdf
 
Relaciona cada �poca con sus caracter�sticas definitorias. Per�od.pdf
Relaciona cada �poca con sus caracter�sticas definitorias.  Per�od.pdfRelaciona cada �poca con sus caracter�sticas definitorias.  Per�od.pdf
Relaciona cada �poca con sus caracter�sticas definitorias. Per�od.pdf
 
Regarding the management of R&D teams after Vandeputte�s diversifica.pdf
Regarding the management of R&D teams after Vandeputte�s diversifica.pdfRegarding the management of R&D teams after Vandeputte�s diversifica.pdf
Regarding the management of R&D teams after Vandeputte�s diversifica.pdf
 
Reflect on your current workplace where you currently interact with .pdf
Reflect on your current workplace where you currently interact with .pdfReflect on your current workplace where you currently interact with .pdf
Reflect on your current workplace where you currently interact with .pdf
 
Reflexiona sobre un cambio profesional importante que hayas experime.pdf
Reflexiona sobre un cambio profesional importante que hayas experime.pdfReflexiona sobre un cambio profesional importante que hayas experime.pdf
Reflexiona sobre un cambio profesional importante que hayas experime.pdf
 
ReinforcementR-4.3 Viruses that perform no explicit malicious beha.pdf
ReinforcementR-4.3 Viruses that perform no explicit malicious beha.pdfReinforcementR-4.3 Viruses that perform no explicit malicious beha.pdf
ReinforcementR-4.3 Viruses that perform no explicit malicious beha.pdf
 
Required 1. prepare the Income Statement for the year ended Decembe.pdf
Required 1. prepare the Income Statement for the year ended Decembe.pdfRequired 1. prepare the Income Statement for the year ended Decembe.pdf
Required 1. prepare the Income Statement for the year ended Decembe.pdf
 
Required Designate where each of the following events would be pre.pdf
Required  Designate where each of the following events would be pre.pdfRequired  Designate where each of the following events would be pre.pdf
Required Designate where each of the following events would be pre.pdf
 
Routes of Administration The nurse is teaching clients with inflamma.pdf
Routes of Administration The nurse is teaching clients with inflamma.pdfRoutes of Administration The nurse is teaching clients with inflamma.pdf
Routes of Administration The nurse is teaching clients with inflamma.pdf
 
Renzo es un l�der entusiasta que cree en sus ideas. Renzo se detiene.pdf
Renzo es un l�der entusiasta que cree en sus ideas. Renzo se detiene.pdfRenzo es un l�der entusiasta que cree en sus ideas. Renzo se detiene.pdf
Renzo es un l�der entusiasta que cree en sus ideas. Renzo se detiene.pdf
 
Romance en la oficina buscando respuestas a tientasDescripci�n de.pdf
Romance en la oficina buscando respuestas a tientasDescripci�n de.pdfRomance en la oficina buscando respuestas a tientasDescripci�n de.pdf
Romance en la oficina buscando respuestas a tientasDescripci�n de.pdf
 
ROBOTICS Currently, roboticists and AI researchers are still strug.pdf
ROBOTICS Currently, roboticists and AI researchers are still strug.pdfROBOTICS Currently, roboticists and AI researchers are still strug.pdf
ROBOTICS Currently, roboticists and AI researchers are still strug.pdf
 
Roberts Rules of Order refer toA.procedural guidelines on the corre.pdf
Roberts Rules of Order refer toA.procedural guidelines on the corre.pdfRoberts Rules of Order refer toA.procedural guidelines on the corre.pdf
Roberts Rules of Order refer toA.procedural guidelines on the corre.pdf
 
RKO-Stanley v. GrazianoEagen, J.On April 30, 1970, RKO-Stanley W.pdf
RKO-Stanley v. GrazianoEagen, J.On April 30, 1970, RKO-Stanley W.pdfRKO-Stanley v. GrazianoEagen, J.On April 30, 1970, RKO-Stanley W.pdf
RKO-Stanley v. GrazianoEagen, J.On April 30, 1970, RKO-Stanley W.pdf
 
Robert and Charles are trying to decide what form of business to for.pdf
Robert and Charles are trying to decide what form of business to for.pdfRobert and Charles are trying to decide what form of business to for.pdf
Robert and Charles are trying to decide what form of business to for.pdf
 

Recently uploaded

Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 

Recently uploaded (20)

Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 

Requirements Use JavaDo Not Use RecursionDo Not Use Array Lis.pdf

  • 1. Requirements : Use Java Do Not Use Recursion Do Not Use Array List Use The Methods Provided Use What Is Provided Only Make And Use The Helper Methods The Instructions Say You Can Only Provide The Answer Code Thank You ! I'm Having The Hardest Time Understanding This Maze Solving with Stacks Consider a maze made up of rectangular array of squares, such as the following one: X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X Figure 1--- A sample maze The X blocks represent a blocked square and form the walls of the maze. Let us consider mazes that have only one entrance and one exit, as in our example. Beginning at the entrance at the top left side of the maze, find a path to the exit at the bottom right side. You can move only up, down, left, or right. Square is either clear or blocked by an X character. Let a two-dimensional array represent the maze. Use a stack data structure to find a path through the maze. Some mazes might have more than one successful path, while others might have no path. Hints: The primary consideration is that if you reach a dead end, you need to be able to backtrack along the path to the point where you can try a different path. The stack data structure makes it possible to store the current path and backtrack if necessary. Every clear position visited in the current path is pushed to the stack and if a dead end is reached, the previous position is popped from the stack to backtrack. You need to have a loop that begins with the start position and
  • 2. pushes it into the stack then moves to a neighboring cell until either the goal position is reached, or the stack becomes empty. Make sure to mark each clear array cell you move to as visited to avoid checking it again and getting stuck in an infinite loop. For example, each array cell can have three different values: X for blocked, V for visited, and for clear. A dead end is an array cell whose all neighbors are either blocked or already visited. Maze Solving with Stacks CSC 385 What you need to do: There are four files you should pay attention to: Position.java: a class to store the position of an array cell. It has two attributes: row and column along with their accessor and mutator methods. It also has an equals method that checks for equality of two Position objects. Maze.java: a class to store a maze. It has 3 attributes: a two-dimensional character array which represents the maze, a Position object to represent the start location, and another Position object to represent the stop location. MazeSolver: This class contains one static method, solve. It accepts a maze and returns an array of Positions that is used to traverse the maze if the maze is solvable. If the maze is not solvable then an empty array is returned. o Keep in mind that stacks store objects in reverse order so be sure to return the position array in the correct order. Tester: a sample driver class which calls the traverse method on a maze in either the SolvableMaze, UnsolvableMaze, or HugeSolvableMaze files. These should be at the root of the project folder. You only need to implement the solve method in the MazeSolver.java class. This method receives the maze to solve as a parameter and returns an array of Position objects which stores a solution to the maze if such solution exists; otherwise, it returns an empty array. Note: There might be more than one possible solution to a maze, depending on the ordering in which the neighboring cells are visited at each location. You can do whatever order you want if the maze is solved. For instance, First move left, if the left neighbor is not clear, then move right, if the right neighbor is not clear, then move up, if it is not clear, then move down.
  • 3. You may create any additional helper methods to aid you. For instance, you may make a method to convert the stack to a necessary array. Just remember, when you grab the information from a stack you are getting in the reverse order you push them. You must solve the problem using a Stack. You may use the built-in stack library but use of any other data structure is prohibited apart from constructing the final Position array result. Recursion is also not allowed. What you need to turn in: You need to submit the MazeSolver.java file containing your implementation of the solve method. Maze Solving with Stacks CSC 385 Rubric Stack is utilized 75 Iterative solution 5 Returns correct solutions to solvable mazes 10 Returns correct solutions to unsolvable mazes 10 Additional Notes and Helpful Hints First hint I have is to not be afraid of creating additional variables to store information. For instance, you must move up, down, left, and right (or north, south, west, and east). Creating Position objects to represent these movements is perfectly acceptable. You will also want to create an object that is the walker of the maze. This walker keeps the current position in the maze. Other than push, pop, and peek on the Stack class, isEmpty is also a useful method. The maze class contains a bunch of methods that is meant to help you. Read what the methods do and decide which ones you want to use for your solution. Read the code given to you FIRST before starting to write your code so you can utilize it. It is there to make your life easier, not harder. Try to translate what you want to do in terms of the stack operations. For instance, if you find yourself at a dead end then you want to move back to a previous position. This means you will need to first pop the top position, which contains the spot located at the dead end, then peek to see where you need to
  • 4. be. Your stack should be declared and initialized as such: Stack __Give it a name__ = new Stack(); where you can name it whatever you want. Moving in a two-dimensional array requires the following math: Move up (North) Row + 1 Move down (South) Row - 1 Move left (West) Column - 1 Move right (East) Column + 1 The Provided Code : Plus The Method I Need Solved ! Position.java public class Position { /*************************** * Attributes ****************************/ private int row; private int column; /*************************** * Constructor * * @param row * @param column ***************************/ public Position(int row, int column) { this.row = row; this.column = column; } /************************** * Checks two positions for equality. Two positions are equal if the have the * same row and column numbers. *************************/ public boolean equals(Object obj) { if (obj == null) { return false; }
  • 5. if (!(obj instanceof Position)) { return false; } Position otherPosition = (Position) obj; return (otherPosition.row == row && otherPosition.column == column); } public String toString() { return "row:" + row + " column:" + column; } /************************** * Getter and Setter methods * * @return */ public int getRow() { return row; } public int getColumn() { return column; } } Maze.java public class Maze { /** * Two dimensional array to represent a maze */ private final char[][] maze; private final Position start, end; /** * Constructor initializing the maze array * * @param maze */ public Maze(char[][] maze, Position start, Position end) { this.maze = maze; if (validPosition(start)) {
  • 6. this.start = start; } else { throw new PositionNotValidException("The start position is valid for the maze: " + start); } if (validPosition(end)) { this.end = end; } else { throw new PositionNotValidException("The stop position is valid for the maze: " + end); } } /** * Returns the start position object. * * @return The start position. */ public Position getStart() { return start; } /** * Returns the stop position object. * * @return */ public Position getEnd() { return end; } /** * Returns the number of rows the maze has. * * @return The number of rows. */ public int numRows() { return maze.length; } /** * Returns the number of columns the row of the maze has.
  • 7. * * @param row The row to get the length of. * @return The length of the row in the maze. */ public int numCols(int row) { return maze[row].length; } /** * Tests if row and column are valid within the two dimensional array. Will * return true iff row is between 0 and maze.length-1 and column is between 0 * and maze[row].length - 1. * * @param row Represents the array to retrieve from maze. * @param col Represents the character to retrieve from the array at maze[row]. * @return True iff the row and column are valid indices of maze otherwise * false. */ public boolean validPosition(int row, int col) { if (row >= 0 && row < maze.length) { if (col >= 0 && col < maze[row].length) { return true; } } return false; } /** * Tests if the row and column stored in pos are valid. Drops to the * validPosition(int row, int col) method. * * @param pos The position to test. * @return True iff pos is valid inside the maze otherwise false. */ public boolean validPosition(Position pos) { return validPosition(pos.getRow(), pos.getColumn()); } /**
  • 8. * Returns the character at pos. * * @param pos The position to retrieve the character at. * @return The character at maze[pos.row][pos.column] * @throws PositionNotValidException if the position is now within the maze. */ public char getAt(Position pos) { if (validPosition(pos)) { return maze[pos.getRow()][pos.getColumn()]; } else { String msg = String.format("The position given is not valid: %s", pos.toString()); throw new PositionNotValidException(msg); } } /** * Retrieves the character at maze[row][column]. * * @param row The row to retrieve the character from. * @param column The column to retrieve the character from. * @return The character at position row, column * @throws PositionNotValidException if the row or column are not within bounds. */ public char getAt(int row, int column) { if (validPosition(row, column)) { return maze[row][column]; } else { String msg = String.format("The row and column given is not valid: row %d col %d", row, column); throw new PositionNotValidException(msg); } } /** * Sets a character at a specified position. * * @param pos The position to set the character at. * @param c The character to set at position.
  • 9. * @throws PositionNotValidException if the position passed in is not valid * within the maze. */ public void setAt(Position pos, char c) { if (validPosition(pos)) { setAt(pos.getRow(), pos.getColumn(), c); } else { String msg = String.format("The position given is not valid: %s", pos.toString()); throw new PositionNotValidException(msg); } } /** * Sets a character at a specified row and column. * * @param pos The position to set the character at. * @param c The character to set at position. * @throws PositionNotValidException if the position passed in is not valid * within the maze. */ public void setAt(int row, int column, char c) { if (validPosition(row, column)) { maze[row][column] = c; } else { String msg = String.format("The row and column given is not valid: row %d col %d", row, column); throw new PositionNotValidException(msg); } } /*** METHODS NOT NEEDED TO HELP SOLVE THE PROBLEM. ****/ /*** YOU DO NOT NEED TO USE THESE METHODS AS THEY ****/ /*** ARE USED IN THE MAIN CLASS. ****/ public Maze clone() { char clone[][] = new char[maze.length][]; for (int r = 0; r < maze.length; r++) { clone[r] = new char[maze[r].length]; for (int c = 0; c < maze[r].length; c++) {
  • 10. clone[r][c] = maze[r][c]; } } return new Maze(clone, start, end); } public String toString() { StringBuffer sb = new StringBuffer(); for (int r = 0; r < maze.length; r++) { sb.append(maze[r]); sb.append("n"); } return sb.toString(); } } MazeSolver.java - ONE THAT I NEED A HELP WITH!! import java.util.Stack; /** * Notes: * * The start and end position are contained within the maze object. Use the * getStart() and getEnd() methods. * */ public class MazeSolver { /** * You need to implement this method * * @param maze: The maze to be solved. * @return An array of Position which stores a solution to the maze. If a * solution is not found a null value should be returned. */ public static Position[] solve(Maze maze) { return null; } }