The text file looks like so:
6 6
5 5 5 5 5 5
0 0 0 0 0 5
5 5 0 5 0 5
5 5 0 5 5 5
5 0 0 0 0 0
5 5 5 5 5 5
1 0
I have written code to read the array size and the contents, which is as follows:
package programfour;
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
public class ArrayReader {
public static void main(String[] args) throws FileNotFoundException{
File inputFile = new File("maze1.txt");
Scanner sc = new Scanner(inputFile);
int arrayRowSize = sc.nextInt();
int arrayColumnSize = sc.nextInt();
int[][] mazeArray = new int[arrayRowSize][arrayColumnSize];
for(int i = 0; i < arrayRowSize; i++){
for(int j = 0; j < arrayColumnSize; j++){
mazeArray[i][j] = sc.nextInt();
}
}
sc.nextLine();
for(int i = 0; i < mazeArray.length; i++){
for(int j = 0; j < mazeArray[i].length; j++){
System.out.print(mazeArray[i][j]);
}
System.out.println();
}
sc.close();
}
}
A stack class and an emptystackexception class was provided to us as is as follows:
package stackpackage;
import java.util.LinkedList;
public class Stack {
private LinkedList stack;
public Stack() {
stack = new LinkedList();
}
public boolean isEmpty() {
return stack.size() == 0;
}
public Object pop() {
if (isEmpty()) {
throw new EmptyStackException();
}
return stack.removeFirst();
}
public void push(Object obj) {
stack.addFirst(obj);
}
public Object peek() {
if (isEmpty()) {
throw new EmptyStackException();
}
return stack.peek();
}
}
public class EmptyStackException extends RuntimeException {
public EmptyStackException(String msg) {
super(msg);
}
public EmptyStackException() {
super();
}
}
And we have also had a Coordinate class given to us...:
package programfour;
import stackpackage.*;
public class Coordinate {
private Integer row;
private Integer column;
public Coordinate(Integer row, Integer column){
this.row = row;
this.column= column;
}
public void setRow(Integer row){
this.row = row;
}
public void setColumn(Integer column){
this.column = column;
}
public Integer getRow(){
return row;
}
public Integer getColumn(){
return column;
}
public String toString(){
return "<" + row.toString() + "," + column.toString() + ">";
}
}
I am at a complete loss of what the next step here would be and if someone could point me in the right direction I would be ecstatic.

New Topic/Question
Reply



MultiQuote



|