SlideShare a Scribd company logo
java question: "Fill the add statement area"
Project is to work with stacks.
package p2;
public class Coordinate {
public int x;
public int y;
public Coordinate( int x, int y ) {
this.x = x;
this.y = y;
}
public String toString() {
return "(" + this.x + "," + this.y + ")";
}
@Override
public boolean equals( Object object ) {
if( object == null ) {
return false;
}
if( ! Coordinate.class.isAssignableFrom( object.getClass() )) {
return false;
}
final Coordinate other = (Coordinate) object;
return this.x == other.x && this.y == other.y;
}
}
package p2;
public class Coordinate {
public int x;
public int y;
public Coordinate( int x, int y ) {
this.x = x;
this.y = y;
}
public String toString() {
return "(" + this.x + "," + this.y + ")";
}
@Override
public boolean equals( Object object ) {
if( object == null ) {
return false;
}
if( ! Coordinate.class.isAssignableFrom( object.getClass() )) {
return false;
}
final Coordinate other = (Coordinate) object;
return this.x == other.x && this.y == other.y;
}
}
package p2;
import java.util.Vector;
public class Maze {
private char[][] maze;
private int height;
private int width;
/**
* Create a new Maze of the specified height and width, initializing every
* location as empty, with a ' '.
**/
public Maze( int width, int height ) {
// ADD STATEMENTS HERE
}
/**
* Mutator to allow us to set the specified Coordinate as blocked,
* marking it with a 'X'
**/
public void setBlocked( Coordinate coord ) {
// ADD STATEMENTS HERE
}
/**
* Mutator to allow us to set the specified Coordinate as having been visited,
* marking it with a '*'
**/
public void setVisited( Coordinate coord ) {
// ADD STATEMENTS HERE
}
/**
* Mutator to allow us to set the specified Coordinate as part of the path solution,
* marking it with a '.'
**/
public void setPath( Coordinate coord ) {
// ADD STATEMENTS HERE
}
/**
* Returns the character at the locatio specified by the Coordinate
**/
public char at( Coordinate coord ) {
// ADD STATEMENTS HERE
}
/**
* Returns a Coordinate array containing all Coordinates that are clear around
* the specified coordinate.
**/
public Coordinate[] clearAround( Coordinate coord ) {
Vector vector = new Vector();
// ADD STATEMENTS HERE
// Look at each of the locations around the specified Coordinate, and add it
// to the vector if it is clear (i.e. a space)
return vector.toArray( new Coordinate[0] );
}
/**
* Returns a Coordinate that provides the entrance location in this maze.
**/
public Coordinate start() {
return new Coordinate( 0, 1 );
}
/**
* Returns a Coordinate that provides the exit location from this maze.
**/
public Coordinate end() {
// ADD STATEMENTS HERE
}
/**
* The toString() method is responsible for creating a String representation
* of the Maze. See the project specification for sample output. Note that
* the String representation adds numbers across the top and side of the Maze
* to show the Coordinates of each cell in the maze.
**/
public String toString() {
StringBuilder buffer = new StringBuilder();
// ADD STATEMENTS HERE
// First, print out the column headings
// Next, print out each row in the maze - note the spaces between
// cells to facilitate reading. Each row should include its row number.
return buffer.toString();
}
}
package p2;
import java.util.Vector;
public class Maze {
private char[][] maze;
private int height;
private int width;
/**
* Create a new Maze of the specified height and width, initializing every
* location as empty, with a ' '.
**/
public Maze( int width, int height ) {
// ADD STATEMENTS HERE
}
/**
* Mutator to allow us to set the specified Coordinate as blocked,
* marking it with a 'X'
**/
public void setBlocked( Coordinate coord ) {
// ADD STATEMENTS HERE
}
/**
* Mutator to allow us to set the specified Coordinate as having been visited,
* marking it with a '*'
**/
public void setVisited( Coordinate coord ) {
// ADD STATEMENTS HERE
}
/**
* Mutator to allow us to set the specified Coordinate as part of the path solution,
* marking it with a '.'
**/
public void setPath( Coordinate coord ) {
// ADD STATEMENTS HERE
}
/**
* Returns the character at the locatio specified by the Coordinate
**/
public char at( Coordinate coord ) {
// ADD STATEMENTS HERE
}
/**
* Returns a Coordinate array containing all Coordinates that are clear around
* the specified coordinate.
**/
public Coordinate[] clearAround( Coordinate coord ) {
Vector vector = new Vector();
// ADD STATEMENTS HERE
// Look at each of the locations around the specified Coordinate, and add it
// to the vector if it is clear (i.e. a space)
return vector.toArray( new Coordinate[0] );
}
/**
* Returns a Coordinate that provides the entrance location in this maze.
**/
public Coordinate start() {
return new Coordinate( 0, 1 );
}
/**
* Returns a Coordinate that provides the exit location from this maze.
**/
public Coordinate end() {
// ADD STATEMENTS HERE
}
/**
* The toString() method is responsible for creating a String representation
* of the Maze. See the project specification for sample output. Note that
* the String representation adds numbers across the top and side of the Maze
* to show the Coordinates of each cell in the maze.
**/
public String toString() {
StringBuilder buffer = new StringBuilder();
// ADD STATEMENTS HERE
// First, print out the column headings
// Next, print out each row in the maze - note the spaces between
// cells to facilitate reading. Each row should include its row number.
return buffer.toString();
}
}
package p2;
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
public class MazeReader {
private String fileName;
private Maze maze;
public MazeReader( String fileName ) {
this.fileName = fileName;
this.maze = null;
}
public Maze open() throws FileNotFoundException {
Scanner scanner = new Scanner( new File( this.fileName ));
int width = scanner.nextInt();
int height = scanner.nextInt();
this.maze = new Maze( width, height );
// Remove new line after int
scanner.nextLine();
// ADD STATEMENTS HERE
// You will need to read in each line using the Scanner, and provide
// the row number and the line to the addLine method to add it to the Maze
return this.maze;
}
private void addLine( int row, String line ) {
// ADD STATEMENTS HERE
}
public static void main( String[] args ) throws FileNotFoundException {
MazeReader reader = new MazeReader( "sampleMaze.txt" );
Maze maze = reader.open();
System.out.println( maze );
System.out.println( maze.at( new Coordinate( 0, 0 )));
System.out.println( maze.at( new Coordinate( 0, 1 )));
}
}
package p2;
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
public class MazeReader {
private String fileName;
private Maze maze;
public MazeReader( String fileName ) {
this.fileName = fileName;
this.maze = null;
}
public Maze open() throws FileNotFoundException {
Scanner scanner = new Scanner( new File( this.fileName ));
int width = scanner.nextInt();
int height = scanner.nextInt();
this.maze = new Maze( width, height );
// Remove new line after int
scanner.nextLine();
// ADD STATEMENTS HERE
// You will need to read in each line using the Scanner, and provide
// the row number and the line to the addLine method to add it to the Maze
return this.maze;
}
private void addLine( int row, String line ) {
// ADD STATEMENTS HERE
}
public static void main( String[] args ) throws FileNotFoundException {
MazeReader reader = new MazeReader( "sampleMaze.txt" );
Maze maze = reader.open();
System.out.println( maze );
System.out.println( maze.at( new Coordinate( 0, 0 )));
System.out.println( maze.at( new Coordinate( 0, 1 )));
}
}
package p2;
import java.io.FileNotFoundException;
public class MazeSolver {
private Maze maze;
private LinkedStack path;
public MazeSolver( Maze maze ) {
// ADD STATEMENTS HERE
}
public void solve() {
// ADD STATEMENTS HERE
// Add the starting Coordinate to the maze, and while the Stack has
// entries, and the top of the Stack is not the end, continue searching
// for the path
}
public static void main( String[] args ) throws FileNotFoundException {
MazeReader reader = new MazeReader( "sampleMaze.txt" );
Maze maze = reader.open();
MazeSolver solver = new MazeSolver( maze );
System.out.println( "Before solving" );
System.out.println( maze );
System.out.println( "Start is " + maze.start() );
System.out.println( "End is " + maze.end() );
solver.solve();
System.out.println( "After solving (. shows solution, o shows visited)" );
System.out.println( maze );
}
}
package p2;
import java.io.FileNotFoundException;
public class MazeSolver {
private Maze maze;
private LinkedStack path;
public MazeSolver( Maze maze ) {
// ADD STATEMENTS HERE
}
public void solve() {
// ADD STATEMENTS HERE
// Add the starting Coordinate to the maze, and while the Stack has
// entries, and the top of the Stack is not the end, continue searching
// for the path
}
public static void main( String[] args ) throws FileNotFoundException {
MazeReader reader = new MazeReader( "sampleMaze.txt" );
Maze maze = reader.open();
MazeSolver solver = new MazeSolver( maze );
System.out.println( "Before solving" );
System.out.println( maze );
System.out.println( "Start is " + maze.start() );
System.out.println( "End is " + maze.end() );
solver.solve();
System.out.println( "After solving (. shows solution, o shows visited)" );
System.out.println( maze );
}
}
Consider a maze made up of a rectangular array of squares. The maze will contain a character
(either +, -, or |) to represent a blocked square, and to form the walls of the maze. Mazes will
have only one entrance at the Coordinate (0, 1), with only one exit in the lower right hand corner
of the maze.
Beginning at the entrance to the maze, find a path to the exit at the bottom right of the maze. You
may only move up, down, left, and right. Each square in the maze can be in one of four states:
clear (space), blocked (X), path (.), or visited (*). Initially, after the maze has been read in from
the file, each square will be either clear or blocked. If a square lies on a successful path, mark it
with a period. If you visit a square but it does not lead to a successful path, mark it as visited
with asterisk.
Consider a maze made up of a rectangular array of squares. The maze will contain a character
(either +, -, or |) to represent a blocked square, and to form the walls of the maze. Mazes will
have only one entrance at the Coordinate (0, 1), with only one exit in the lower right hand corner
of the maze.
Beginning at the entrance to the maze, find a path to the exit at the bottom right of the maze. You
may only move up, down, left, and right. Each square in the maze can be in one of four states:
clear (space), blocked (X), path (.), or visited (*). Initially, after the maze has been read in from
the file, each square will be either clear or blocked. If a square lies on a successful path, mark it
with a period. If you visit a square but it does not lead to a successful path, mark it as visited
with asterisk.
Solution
Got with two methods which are mainly required to run the main program:-
public Maze(int width,int height{
if(Maze.maze == null) {
throw new IllegalStateException("Error in setting the size");
}
if(width < 0 || width >= maze.length) {
throw new IllegalArgumentException("Row is Invalid.");
}
if(height < 0 || height >= maze[0].length) {
throw new IllegalArgumentException("Column in Invalid");
}
this.width = width;
this.height = height;
widthMinus1 = (width - 1);
heightMinus1 = (height - 1);
}
We are using the boolean array visited[][] which will set the value to true or false , if the path has
been
traversed already.
private boolean[][] visited = true;
public void solve(char[][]maze)
{
int x = maze[0].length;
int y = maze.length-2;
int d = -1;
boolean ok = false;
recursivesolution(maze,x,y,d);
}
// Defined for solving it recursively
public void recursivesolution(char[][]maze,int x, int y, int d)
{
boolean bool = false;
for (int j = 0;j<4 &&!bool;j++)
if (j!= d)
switch (j)
{
// Check for up right down and left
case 0:
if (maze[y-1][x] == ' ')
bool = recursivesolution(maze, x, y - 2, 2);
break;
case 1:
if (maze[y][x+1] == ' ')
bool = recursivesolution(maze, x + 2, y, 3);
break;
case 2:
if (maze[y+1][x] == ' ')
bool = recursivesolution(maze, x, y + 2, 0);
break;
case 3:
if (maze[y][x-1] == ' ')
bool = recursivesolution(maze, x - 2, y, 1);
break;
}
if (x == 1 && y == 1)
bool = true;
}

More Related Content

Similar to java question Fill the add statement areaProject is to wo.pdf

Keywords of java
Keywords of javaKeywords of java
Keywords of java
Jani Harsh
 
There is something wrong with my program-- (once I do a for view all t.pdf
There is something wrong with my program-- (once I do a for view all t.pdfThere is something wrong with my program-- (once I do a for view all t.pdf
There is something wrong with my program-- (once I do a for view all t.pdf
aashienterprisesuk
 
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfHow do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
mail931892
 
Using NetBeansImplement a queue named QueueLL using a Linked List .pdf
Using NetBeansImplement a queue named QueueLL using a Linked List .pdfUsing NetBeansImplement a queue named QueueLL using a Linked List .pdf
Using NetBeansImplement a queue named QueueLL using a Linked List .pdf
siennatimbok52331
 
In this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdfIn this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdf
contact41
 
Java Generics
Java GenericsJava Generics
Java Generics
jeslie
 
StackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfStackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdf
ARCHANASTOREKOTA
 
Frequency .java Word frequency counter package frequ.pdf
Frequency .java  Word frequency counter  package frequ.pdfFrequency .java  Word frequency counter  package frequ.pdf
Frequency .java Word frequency counter package frequ.pdf
arshiartpalace
 
student start_code_U08223_cwk1 (1).DS_Store__MACOSXstudent.docx
student start_code_U08223_cwk1 (1).DS_Store__MACOSXstudent.docxstudent start_code_U08223_cwk1 (1).DS_Store__MACOSXstudent.docx
student start_code_U08223_cwk1 (1).DS_Store__MACOSXstudent.docx
hanneloremccaffery
 
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfHow do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
mail931892
 
-- USING UNITY TRYING TO CREATE A CLICK TO PATH- THAT YOU CLICK ON AND.pdf
-- USING UNITY TRYING TO CREATE A CLICK TO PATH- THAT YOU CLICK ON AND.pdf-- USING UNITY TRYING TO CREATE A CLICK TO PATH- THAT YOU CLICK ON AND.pdf
-- USING UNITY TRYING TO CREATE A CLICK TO PATH- THAT YOU CLICK ON AND.pdf
ganisyedtrd
 
Java Class Design
Java Class DesignJava Class Design
Java Class Design
Ganesh Samarthyam
 
Creating Interface- Practice Program 6.docx
Creating Interface- Practice Program 6.docxCreating Interface- Practice Program 6.docx
Creating Interface- Practice Program 6.docx
R.K.College of engg & Tech
 
Production.javapublic class Production {    Declaring instance.pdf
Production.javapublic class Production {    Declaring instance.pdfProduction.javapublic class Production {    Declaring instance.pdf
Production.javapublic class Production {    Declaring instance.pdf
sooryasalini
 
java write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdfjava write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdf
arjuntelecom26
 
Tested on EclipseBoth class should be in same package.pdf
Tested on EclipseBoth class should be in same package.pdfTested on EclipseBoth class should be in same package.pdf
Tested on EclipseBoth class should be in same package.pdf
anupamagarud8
 
Object Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsObject Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ Exams
MuhammadTalha436
 
Ruby Programming Assignment Help
Ruby Programming Assignment HelpRuby Programming Assignment Help
Ruby Programming Assignment Help
HelpWithAssignment.com
 
Ruby Programming Assignment Help
Ruby Programming Assignment HelpRuby Programming Assignment Help
Ruby Programming Assignment Help
HelpWithAssignment.com
 
3. Объекты, классы и пакеты в Java
3. Объекты, классы и пакеты в Java3. Объекты, классы и пакеты в Java
3. Объекты, классы и пакеты в Java
DEVTYPE
 

Similar to java question Fill the add statement areaProject is to wo.pdf (20)

Keywords of java
Keywords of javaKeywords of java
Keywords of java
 
There is something wrong with my program-- (once I do a for view all t.pdf
There is something wrong with my program-- (once I do a for view all t.pdfThere is something wrong with my program-- (once I do a for view all t.pdf
There is something wrong with my program-- (once I do a for view all t.pdf
 
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfHow do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
 
Using NetBeansImplement a queue named QueueLL using a Linked List .pdf
Using NetBeansImplement a queue named QueueLL using a Linked List .pdfUsing NetBeansImplement a queue named QueueLL using a Linked List .pdf
Using NetBeansImplement a queue named QueueLL using a Linked List .pdf
 
In this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdfIn this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdf
 
Java Generics
Java GenericsJava Generics
Java Generics
 
StackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfStackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdf
 
Frequency .java Word frequency counter package frequ.pdf
Frequency .java  Word frequency counter  package frequ.pdfFrequency .java  Word frequency counter  package frequ.pdf
Frequency .java Word frequency counter package frequ.pdf
 
student start_code_U08223_cwk1 (1).DS_Store__MACOSXstudent.docx
student start_code_U08223_cwk1 (1).DS_Store__MACOSXstudent.docxstudent start_code_U08223_cwk1 (1).DS_Store__MACOSXstudent.docx
student start_code_U08223_cwk1 (1).DS_Store__MACOSXstudent.docx
 
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfHow do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
 
-- USING UNITY TRYING TO CREATE A CLICK TO PATH- THAT YOU CLICK ON AND.pdf
-- USING UNITY TRYING TO CREATE A CLICK TO PATH- THAT YOU CLICK ON AND.pdf-- USING UNITY TRYING TO CREATE A CLICK TO PATH- THAT YOU CLICK ON AND.pdf
-- USING UNITY TRYING TO CREATE A CLICK TO PATH- THAT YOU CLICK ON AND.pdf
 
Java Class Design
Java Class DesignJava Class Design
Java Class Design
 
Creating Interface- Practice Program 6.docx
Creating Interface- Practice Program 6.docxCreating Interface- Practice Program 6.docx
Creating Interface- Practice Program 6.docx
 
Production.javapublic class Production {    Declaring instance.pdf
Production.javapublic class Production {    Declaring instance.pdfProduction.javapublic class Production {    Declaring instance.pdf
Production.javapublic class Production {    Declaring instance.pdf
 
java write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdfjava write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdf
 
Tested on EclipseBoth class should be in same package.pdf
Tested on EclipseBoth class should be in same package.pdfTested on EclipseBoth class should be in same package.pdf
Tested on EclipseBoth class should be in same package.pdf
 
Object Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ ExamsObject Oriented Solved Practice Programs C++ Exams
Object Oriented Solved Practice Programs C++ Exams
 
Ruby Programming Assignment Help
Ruby Programming Assignment HelpRuby Programming Assignment Help
Ruby Programming Assignment Help
 
Ruby Programming Assignment Help
Ruby Programming Assignment HelpRuby Programming Assignment Help
Ruby Programming Assignment Help
 
3. Объекты, классы и пакеты в Java
3. Объекты, классы и пакеты в Java3. Объекты, классы и пакеты в Java
3. Объекты, классы и пакеты в Java
 

More from dbrienmhompsonkath75

Give examples of system which can achieve some security requirement.pdf
Give examples of system which can achieve some security requirement.pdfGive examples of system which can achieve some security requirement.pdf
Give examples of system which can achieve some security requirement.pdf
dbrienmhompsonkath75
 
Help me with these questions please.1. Name four characteristics t.pdf
Help me with these questions please.1. Name four characteristics t.pdfHelp me with these questions please.1. Name four characteristics t.pdf
Help me with these questions please.1. Name four characteristics t.pdf
dbrienmhompsonkath75
 
Describe current and emerging roles of the patient record in HIT toda.pdf
Describe current and emerging roles of the patient record in HIT toda.pdfDescribe current and emerging roles of the patient record in HIT toda.pdf
Describe current and emerging roles of the patient record in HIT toda.pdf
dbrienmhompsonkath75
 
Dont change the templates, and just fill out the TODO parts on .pdf
Dont change the templates, and just fill out the  TODO parts on .pdfDont change the templates, and just fill out the  TODO parts on .pdf
Dont change the templates, and just fill out the TODO parts on .pdf
dbrienmhompsonkath75
 
Directions Problem 1. A female with Muppetrus bristle mates with a .pdf
Directions Problem 1. A female with Muppetrus bristle mates with a .pdfDirections Problem 1. A female with Muppetrus bristle mates with a .pdf
Directions Problem 1. A female with Muppetrus bristle mates with a .pdf
dbrienmhompsonkath75
 
Describe the roll of each of the following in membrane transport a.pdf
Describe the roll of each of the following in membrane transport a.pdfDescribe the roll of each of the following in membrane transport a.pdf
Describe the roll of each of the following in membrane transport a.pdf
dbrienmhompsonkath75
 
Compare and contrast transactional and transformational leadership.pdf
Compare and contrast transactional and transformational leadership.pdfCompare and contrast transactional and transformational leadership.pdf
Compare and contrast transactional and transformational leadership.pdf
dbrienmhompsonkath75
 
Calculator Which of the following is not an asset Oa, owners equi.pdf
Calculator Which of the following is not an asset Oa, owners equi.pdfCalculator Which of the following is not an asset Oa, owners equi.pdf
Calculator Which of the following is not an asset Oa, owners equi.pdf
dbrienmhompsonkath75
 
You are installing a KVM switch for a small business customer so tha.pdf
You are installing a KVM switch for a small business customer so tha.pdfYou are installing a KVM switch for a small business customer so tha.pdf
You are installing a KVM switch for a small business customer so tha.pdf
dbrienmhompsonkath75
 
Why is metabolism important for physiological processesSolution.pdf
Why is metabolism important for physiological processesSolution.pdfWhy is metabolism important for physiological processesSolution.pdf
Why is metabolism important for physiological processesSolution.pdf
dbrienmhompsonkath75
 
Which macromolecule is primarily responsible for producing the pheno.pdf
Which macromolecule is primarily responsible for producing the pheno.pdfWhich macromolecule is primarily responsible for producing the pheno.pdf
Which macromolecule is primarily responsible for producing the pheno.pdf
dbrienmhompsonkath75
 
which invertebrate phylum is considered the most evolutionarily succe.pdf
which invertebrate phylum is considered the most evolutionarily succe.pdfwhich invertebrate phylum is considered the most evolutionarily succe.pdf
which invertebrate phylum is considered the most evolutionarily succe.pdf
dbrienmhompsonkath75
 
What suggestions would you offer to parents and teachers who want to.pdf
What suggestions would you offer to parents and teachers who want to.pdfWhat suggestions would you offer to parents and teachers who want to.pdf
What suggestions would you offer to parents and teachers who want to.pdf
dbrienmhompsonkath75
 
What is the F2 generation when the F1 generation of +++y cv f is cr.pdf
What is the F2 generation when the F1 generation of +++y cv f is cr.pdfWhat is the F2 generation when the F1 generation of +++y cv f is cr.pdf
What is the F2 generation when the F1 generation of +++y cv f is cr.pdf
dbrienmhompsonkath75
 
What features on the plasmid allows it to replicate independent o.pdf
What features on the plasmid allows it to replicate independent o.pdfWhat features on the plasmid allows it to replicate independent o.pdf
What features on the plasmid allows it to replicate independent o.pdf
dbrienmhompsonkath75
 
What are the use of Fibonacci numbers or the Golden Ratio in nature,.pdf
What are the use of Fibonacci numbers or the Golden Ratio in nature,.pdfWhat are the use of Fibonacci numbers or the Golden Ratio in nature,.pdf
What are the use of Fibonacci numbers or the Golden Ratio in nature,.pdf
dbrienmhompsonkath75
 
Based on the following schematic with 3 D flip-flops, Write complete .pdf
Based on the following schematic with 3 D flip-flops, Write complete .pdfBased on the following schematic with 3 D flip-flops, Write complete .pdf
Based on the following schematic with 3 D flip-flops, Write complete .pdf
dbrienmhompsonkath75
 
Although O_2 does not participate directly in the reactions of the TC.pdf
Although O_2 does not participate directly in the reactions of the TC.pdfAlthough O_2 does not participate directly in the reactions of the TC.pdf
Although O_2 does not participate directly in the reactions of the TC.pdf
dbrienmhompsonkath75
 
8. Which of the following is NOT a transcriptionally repressed genom.pdf
8. Which of the following is NOT a transcriptionally repressed genom.pdf8. Which of the following is NOT a transcriptionally repressed genom.pdf
8. Which of the following is NOT a transcriptionally repressed genom.pdf
dbrienmhompsonkath75
 
49. Autonomic nervous system function is influenced by A) cerebral co.pdf
49. Autonomic nervous system function is influenced by A) cerebral co.pdf49. Autonomic nervous system function is influenced by A) cerebral co.pdf
49. Autonomic nervous system function is influenced by A) cerebral co.pdf
dbrienmhompsonkath75
 

More from dbrienmhompsonkath75 (20)

Give examples of system which can achieve some security requirement.pdf
Give examples of system which can achieve some security requirement.pdfGive examples of system which can achieve some security requirement.pdf
Give examples of system which can achieve some security requirement.pdf
 
Help me with these questions please.1. Name four characteristics t.pdf
Help me with these questions please.1. Name four characteristics t.pdfHelp me with these questions please.1. Name four characteristics t.pdf
Help me with these questions please.1. Name four characteristics t.pdf
 
Describe current and emerging roles of the patient record in HIT toda.pdf
Describe current and emerging roles of the patient record in HIT toda.pdfDescribe current and emerging roles of the patient record in HIT toda.pdf
Describe current and emerging roles of the patient record in HIT toda.pdf
 
Dont change the templates, and just fill out the TODO parts on .pdf
Dont change the templates, and just fill out the  TODO parts on .pdfDont change the templates, and just fill out the  TODO parts on .pdf
Dont change the templates, and just fill out the TODO parts on .pdf
 
Directions Problem 1. A female with Muppetrus bristle mates with a .pdf
Directions Problem 1. A female with Muppetrus bristle mates with a .pdfDirections Problem 1. A female with Muppetrus bristle mates with a .pdf
Directions Problem 1. A female with Muppetrus bristle mates with a .pdf
 
Describe the roll of each of the following in membrane transport a.pdf
Describe the roll of each of the following in membrane transport a.pdfDescribe the roll of each of the following in membrane transport a.pdf
Describe the roll of each of the following in membrane transport a.pdf
 
Compare and contrast transactional and transformational leadership.pdf
Compare and contrast transactional and transformational leadership.pdfCompare and contrast transactional and transformational leadership.pdf
Compare and contrast transactional and transformational leadership.pdf
 
Calculator Which of the following is not an asset Oa, owners equi.pdf
Calculator Which of the following is not an asset Oa, owners equi.pdfCalculator Which of the following is not an asset Oa, owners equi.pdf
Calculator Which of the following is not an asset Oa, owners equi.pdf
 
You are installing a KVM switch for a small business customer so tha.pdf
You are installing a KVM switch for a small business customer so tha.pdfYou are installing a KVM switch for a small business customer so tha.pdf
You are installing a KVM switch for a small business customer so tha.pdf
 
Why is metabolism important for physiological processesSolution.pdf
Why is metabolism important for physiological processesSolution.pdfWhy is metabolism important for physiological processesSolution.pdf
Why is metabolism important for physiological processesSolution.pdf
 
Which macromolecule is primarily responsible for producing the pheno.pdf
Which macromolecule is primarily responsible for producing the pheno.pdfWhich macromolecule is primarily responsible for producing the pheno.pdf
Which macromolecule is primarily responsible for producing the pheno.pdf
 
which invertebrate phylum is considered the most evolutionarily succe.pdf
which invertebrate phylum is considered the most evolutionarily succe.pdfwhich invertebrate phylum is considered the most evolutionarily succe.pdf
which invertebrate phylum is considered the most evolutionarily succe.pdf
 
What suggestions would you offer to parents and teachers who want to.pdf
What suggestions would you offer to parents and teachers who want to.pdfWhat suggestions would you offer to parents and teachers who want to.pdf
What suggestions would you offer to parents and teachers who want to.pdf
 
What is the F2 generation when the F1 generation of +++y cv f is cr.pdf
What is the F2 generation when the F1 generation of +++y cv f is cr.pdfWhat is the F2 generation when the F1 generation of +++y cv f is cr.pdf
What is the F2 generation when the F1 generation of +++y cv f is cr.pdf
 
What features on the plasmid allows it to replicate independent o.pdf
What features on the plasmid allows it to replicate independent o.pdfWhat features on the plasmid allows it to replicate independent o.pdf
What features on the plasmid allows it to replicate independent o.pdf
 
What are the use of Fibonacci numbers or the Golden Ratio in nature,.pdf
What are the use of Fibonacci numbers or the Golden Ratio in nature,.pdfWhat are the use of Fibonacci numbers or the Golden Ratio in nature,.pdf
What are the use of Fibonacci numbers or the Golden Ratio in nature,.pdf
 
Based on the following schematic with 3 D flip-flops, Write complete .pdf
Based on the following schematic with 3 D flip-flops, Write complete .pdfBased on the following schematic with 3 D flip-flops, Write complete .pdf
Based on the following schematic with 3 D flip-flops, Write complete .pdf
 
Although O_2 does not participate directly in the reactions of the TC.pdf
Although O_2 does not participate directly in the reactions of the TC.pdfAlthough O_2 does not participate directly in the reactions of the TC.pdf
Although O_2 does not participate directly in the reactions of the TC.pdf
 
8. Which of the following is NOT a transcriptionally repressed genom.pdf
8. Which of the following is NOT a transcriptionally repressed genom.pdf8. Which of the following is NOT a transcriptionally repressed genom.pdf
8. Which of the following is NOT a transcriptionally repressed genom.pdf
 
49. Autonomic nervous system function is influenced by A) cerebral co.pdf
49. Autonomic nervous system function is influenced by A) cerebral co.pdf49. Autonomic nervous system function is influenced by A) cerebral co.pdf
49. Autonomic nervous system function is influenced by A) cerebral co.pdf
 

Recently uploaded

1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
Nguyen Thanh Tu Collection
 

Recently uploaded (20)

1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 

java question Fill the add statement areaProject is to wo.pdf

  • 1. java question: "Fill the add statement area" Project is to work with stacks. package p2; public class Coordinate { public int x; public int y; public Coordinate( int x, int y ) { this.x = x; this.y = y; } public String toString() { return "(" + this.x + "," + this.y + ")"; } @Override public boolean equals( Object object ) { if( object == null ) { return false; } if( ! Coordinate.class.isAssignableFrom( object.getClass() )) { return false;
  • 2. } final Coordinate other = (Coordinate) object; return this.x == other.x && this.y == other.y; } } package p2; public class Coordinate { public int x; public int y; public Coordinate( int x, int y ) { this.x = x; this.y = y; } public String toString() { return "(" + this.x + "," + this.y + ")"; } @Override public boolean equals( Object object ) { if( object == null ) { return false; } if( ! Coordinate.class.isAssignableFrom( object.getClass() )) {
  • 3. return false; } final Coordinate other = (Coordinate) object; return this.x == other.x && this.y == other.y; } } package p2; import java.util.Vector; public class Maze { private char[][] maze; private int height; private int width; /** * Create a new Maze of the specified height and width, initializing every * location as empty, with a ' '. **/ public Maze( int width, int height ) { // ADD STATEMENTS HERE } /** * Mutator to allow us to set the specified Coordinate as blocked,
  • 4. * marking it with a 'X' **/ public void setBlocked( Coordinate coord ) { // ADD STATEMENTS HERE } /** * Mutator to allow us to set the specified Coordinate as having been visited, * marking it with a '*' **/ public void setVisited( Coordinate coord ) { // ADD STATEMENTS HERE } /** * Mutator to allow us to set the specified Coordinate as part of the path solution, * marking it with a '.' **/ public void setPath( Coordinate coord ) { // ADD STATEMENTS HERE } /** * Returns the character at the locatio specified by the Coordinate **/ public char at( Coordinate coord ) { // ADD STATEMENTS HERE } /** * Returns a Coordinate array containing all Coordinates that are clear around * the specified coordinate.
  • 5. **/ public Coordinate[] clearAround( Coordinate coord ) { Vector vector = new Vector(); // ADD STATEMENTS HERE // Look at each of the locations around the specified Coordinate, and add it // to the vector if it is clear (i.e. a space) return vector.toArray( new Coordinate[0] ); } /** * Returns a Coordinate that provides the entrance location in this maze. **/ public Coordinate start() { return new Coordinate( 0, 1 ); } /** * Returns a Coordinate that provides the exit location from this maze. **/ public Coordinate end() { // ADD STATEMENTS HERE } /** * The toString() method is responsible for creating a String representation * of the Maze. See the project specification for sample output. Note that * the String representation adds numbers across the top and side of the Maze * to show the Coordinates of each cell in the maze. **/
  • 6. public String toString() { StringBuilder buffer = new StringBuilder(); // ADD STATEMENTS HERE // First, print out the column headings // Next, print out each row in the maze - note the spaces between // cells to facilitate reading. Each row should include its row number. return buffer.toString(); } } package p2; import java.util.Vector; public class Maze { private char[][] maze; private int height; private int width; /** * Create a new Maze of the specified height and width, initializing every * location as empty, with a ' '. **/ public Maze( int width, int height ) { // ADD STATEMENTS HERE }
  • 7. /** * Mutator to allow us to set the specified Coordinate as blocked, * marking it with a 'X' **/ public void setBlocked( Coordinate coord ) { // ADD STATEMENTS HERE } /** * Mutator to allow us to set the specified Coordinate as having been visited, * marking it with a '*' **/ public void setVisited( Coordinate coord ) { // ADD STATEMENTS HERE } /** * Mutator to allow us to set the specified Coordinate as part of the path solution, * marking it with a '.' **/ public void setPath( Coordinate coord ) { // ADD STATEMENTS HERE } /** * Returns the character at the locatio specified by the Coordinate **/ public char at( Coordinate coord ) { // ADD STATEMENTS HERE }
  • 8. /** * Returns a Coordinate array containing all Coordinates that are clear around * the specified coordinate. **/ public Coordinate[] clearAround( Coordinate coord ) { Vector vector = new Vector(); // ADD STATEMENTS HERE // Look at each of the locations around the specified Coordinate, and add it // to the vector if it is clear (i.e. a space) return vector.toArray( new Coordinate[0] ); } /** * Returns a Coordinate that provides the entrance location in this maze. **/ public Coordinate start() { return new Coordinate( 0, 1 ); } /** * Returns a Coordinate that provides the exit location from this maze. **/ public Coordinate end() { // ADD STATEMENTS HERE } /** * The toString() method is responsible for creating a String representation
  • 9. * of the Maze. See the project specification for sample output. Note that * the String representation adds numbers across the top and side of the Maze * to show the Coordinates of each cell in the maze. **/ public String toString() { StringBuilder buffer = new StringBuilder(); // ADD STATEMENTS HERE // First, print out the column headings // Next, print out each row in the maze - note the spaces between // cells to facilitate reading. Each row should include its row number. return buffer.toString(); } } package p2; import java.util.Scanner; import java.io.File; import java.io.FileNotFoundException; public class MazeReader { private String fileName; private Maze maze; public MazeReader( String fileName ) { this.fileName = fileName; this.maze = null;
  • 10. } public Maze open() throws FileNotFoundException { Scanner scanner = new Scanner( new File( this.fileName )); int width = scanner.nextInt(); int height = scanner.nextInt(); this.maze = new Maze( width, height ); // Remove new line after int scanner.nextLine(); // ADD STATEMENTS HERE // You will need to read in each line using the Scanner, and provide // the row number and the line to the addLine method to add it to the Maze return this.maze; } private void addLine( int row, String line ) { // ADD STATEMENTS HERE } public static void main( String[] args ) throws FileNotFoundException { MazeReader reader = new MazeReader( "sampleMaze.txt" ); Maze maze = reader.open();
  • 11. System.out.println( maze ); System.out.println( maze.at( new Coordinate( 0, 0 ))); System.out.println( maze.at( new Coordinate( 0, 1 ))); } } package p2; import java.util.Scanner; import java.io.File; import java.io.FileNotFoundException; public class MazeReader { private String fileName; private Maze maze; public MazeReader( String fileName ) { this.fileName = fileName; this.maze = null; } public Maze open() throws FileNotFoundException { Scanner scanner = new Scanner( new File( this.fileName )); int width = scanner.nextInt(); int height = scanner.nextInt(); this.maze = new Maze( width, height );
  • 12. // Remove new line after int scanner.nextLine(); // ADD STATEMENTS HERE // You will need to read in each line using the Scanner, and provide // the row number and the line to the addLine method to add it to the Maze return this.maze; } private void addLine( int row, String line ) { // ADD STATEMENTS HERE } public static void main( String[] args ) throws FileNotFoundException { MazeReader reader = new MazeReader( "sampleMaze.txt" ); Maze maze = reader.open(); System.out.println( maze ); System.out.println( maze.at( new Coordinate( 0, 0 ))); System.out.println( maze.at( new Coordinate( 0, 1 ))); } } package p2;
  • 13. import java.io.FileNotFoundException; public class MazeSolver { private Maze maze; private LinkedStack path; public MazeSolver( Maze maze ) { // ADD STATEMENTS HERE } public void solve() { // ADD STATEMENTS HERE // Add the starting Coordinate to the maze, and while the Stack has // entries, and the top of the Stack is not the end, continue searching // for the path } public static void main( String[] args ) throws FileNotFoundException { MazeReader reader = new MazeReader( "sampleMaze.txt" ); Maze maze = reader.open(); MazeSolver solver = new MazeSolver( maze ); System.out.println( "Before solving" ); System.out.println( maze ); System.out.println( "Start is " + maze.start() ); System.out.println( "End is " + maze.end() ); solver.solve(); System.out.println( "After solving (. shows solution, o shows visited)" ); System.out.println( maze );
  • 14. } } package p2; import java.io.FileNotFoundException; public class MazeSolver { private Maze maze; private LinkedStack path; public MazeSolver( Maze maze ) { // ADD STATEMENTS HERE } public void solve() { // ADD STATEMENTS HERE // Add the starting Coordinate to the maze, and while the Stack has // entries, and the top of the Stack is not the end, continue searching // for the path } public static void main( String[] args ) throws FileNotFoundException { MazeReader reader = new MazeReader( "sampleMaze.txt" ); Maze maze = reader.open(); MazeSolver solver = new MazeSolver( maze ); System.out.println( "Before solving" ); System.out.println( maze ); System.out.println( "Start is " + maze.start() ); System.out.println( "End is " + maze.end() );
  • 15. solver.solve(); System.out.println( "After solving (. shows solution, o shows visited)" ); System.out.println( maze ); } } Consider a maze made up of a rectangular array of squares. The maze will contain a character (either +, -, or |) to represent a blocked square, and to form the walls of the maze. Mazes will have only one entrance at the Coordinate (0, 1), with only one exit in the lower right hand corner of the maze. Beginning at the entrance to the maze, find a path to the exit at the bottom right of the maze. You may only move up, down, left, and right. Each square in the maze can be in one of four states: clear (space), blocked (X), path (.), or visited (*). Initially, after the maze has been read in from the file, each square will be either clear or blocked. If a square lies on a successful path, mark it with a period. If you visit a square but it does not lead to a successful path, mark it as visited with asterisk. Consider a maze made up of a rectangular array of squares. The maze will contain a character (either +, -, or |) to represent a blocked square, and to form the walls of the maze. Mazes will have only one entrance at the Coordinate (0, 1), with only one exit in the lower right hand corner of the maze. Beginning at the entrance to the maze, find a path to the exit at the bottom right of the maze. You may only move up, down, left, and right. Each square in the maze can be in one of four states: clear (space), blocked (X), path (.), or visited (*). Initially, after the maze has been read in from the file, each square will be either clear or blocked. If a square lies on a successful path, mark it with a period. If you visit a square but it does not lead to a successful path, mark it as visited with asterisk. Solution Got with two methods which are mainly required to run the main program:- public Maze(int width,int height{ if(Maze.maze == null) {
  • 16. throw new IllegalStateException("Error in setting the size"); } if(width < 0 || width >= maze.length) { throw new IllegalArgumentException("Row is Invalid."); } if(height < 0 || height >= maze[0].length) { throw new IllegalArgumentException("Column in Invalid"); } this.width = width; this.height = height; widthMinus1 = (width - 1); heightMinus1 = (height - 1); } We are using the boolean array visited[][] which will set the value to true or false , if the path has been traversed already. private boolean[][] visited = true; public void solve(char[][]maze) { int x = maze[0].length; int y = maze.length-2; int d = -1; boolean ok = false; recursivesolution(maze,x,y,d); } // Defined for solving it recursively public void recursivesolution(char[][]maze,int x, int y, int d) { boolean bool = false; for (int j = 0;j<4 &&!bool;j++) if (j!= d) switch (j) { // Check for up right down and left
  • 17. case 0: if (maze[y-1][x] == ' ') bool = recursivesolution(maze, x, y - 2, 2); break; case 1: if (maze[y][x+1] == ' ') bool = recursivesolution(maze, x + 2, y, 3); break; case 2: if (maze[y+1][x] == ' ') bool = recursivesolution(maze, x, y + 2, 0); break; case 3: if (maze[y][x-1] == ' ') bool = recursivesolution(maze, x - 2, y, 1); break; } if (x == 1 && y == 1) bool = true; }