fork download
  1. import java.io.*;
  2. import java.util.*;
  3. import java.lang.*;
  4. import java.text.*;
  5.  
  6.  
  7. public class MazeSolve1
  8. {
  9. public static void main(String[] args)
  10. {
  11. //Create arrayList of Points
  12. ArrayList<ArrayList<Points>> MAZE = new ArrayList<ArrayList<Points>>();
  13. Scanner in = new Scanner(System.in);
  14.  
  15. //Read File in
  16. System.out.print("Enter the file name: ");
  17. String fileName = in.nextLine();
  18. fileName = fileName.trim();
  19. FileReader reader = new FileReader(fileName+".txt");
  20. Scanner in2 = new Scanner(reader);
  21.  
  22. //Write file out
  23. FileWriter writer = new FileWriter("Numbers.out");
  24. PrintWriter out = new PrintWriter(writer);
  25. boolean done = false;
  26. int maxCol = 0;
  27. int maxRow = 0;
  28.  
  29. while(!done) {
  30.  
  31. //creating array lists
  32. while (in2.hasNextLine()) {
  33. //Read next line
  34. String nextLine = in2.nextLine();
  35. //Tokenize Line
  36. StringTokenizer st = new StringTokenizer(nextLine, " ");
  37. //Create temp ArrayList
  38. ArrayList<ArrayList<Points>> temp = new ArrayList<ArrayList<Points>>();
  39.  
  40. //While there are more tokens
  41. while (st.hasNextToken()) {
  42. String token = st.nextToken();
  43. Points pt = new Points();
  44. temp.add(pt);
  45. maxCol++
  46. }
  47. MAZE.add(temp);
  48. maxRow++;
  49. }
  50.  
  51. //create hold arraylist for max rows of maze -1
  52. //create variables for start x and y coordinates
  53. ArrayList<ArrayList<Points>> hold = new ArrayList<ArrayList<Points>>();
  54. hold = MAZE.get(maxRow - 1);
  55. int startColumn = hold.get(maxCol - 1);
  56. int startRow = hold.get(maxRow - 1);
  57. Point start = new Point();
  58. start.setX(startColumn);
  59. start.setY(startRow);
  60.  
  61. //initialize stack, and push the start position
  62. MyStack<Points> st = new ArrayStack<Points>();
  63. st.push(start.toString1());
  64. //south and east of start are edges of array
  65. start.setSouth(false);
  66. start.setEast(false);
  67.  
  68. //while your position is not equal to point (0,0) [finish]
  69. while (st.peek() != "(0, 0)") {
  70.  
  71. //getting the next coordinate to the North
  72. int nextY = start.getY() - 1;
  73. int nextX = start.getX();
  74.  
  75. //if character to the North is an O it's open and the North flag is true
  76. if (hold.get(nextY) = 'O' && start.getNorth() == true) {
  77. //set flags and push coordinate
  78. start.setNorth(false);
  79. st.push(start.toString1());
  80. }
  81. //else pop from stack
  82. else { st.pop(); }
  83.  
  84. //look at coordinate to the East
  85. nextX = start.getX() + 1;
  86. //if character to the East is a O and the East flag is true
  87. if (hold.get(nextX) = 'O' && start.getEast() == true) {
  88. //set flags and push coordinate
  89. start.setEast(false);
  90. st.push(start.toString1());
  91. }
  92. //else pop from stack
  93. else { st.pop(); }
  94.  
  95. //look at coordinate to the South
  96. nextY = start.getY() + 1;
  97. //if character to the South is a O and the West flag is true
  98. if (hold.get(nextY) = 'O' && start.getSouth() == true) {
  99. //set flags and push coordinate
  100. start.setSouth(false);
  101. st.push(start.toString1());
  102. }
  103. //else pop from stack
  104. else { st.pop() }
  105.  
  106. //keep looping until the top of the stack reads (0, 0)
  107. }
  108.  
  109. done = true;
  110. }
  111.  
  112. //Print the results
  113. System.out.println("---Path taken---");
  114. for (int i = 0; i< st.size(); i++) {
  115. System.out.println(st.pop);
  116. i++
  117. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:45: error: ';' expected
            maxCol++
                    ^
Main.java:104: error: ';' expected
        else { st.pop() }
                       ^
Main.java:116: error: ';' expected
    i++
       ^
Main.java:117: error: reached end of file while parsing
}
 ^
4 errors
stdout
Standard output is empty