Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. public CircuitBoard(String filename) throws FileNotFoundException
  2. {
  3.  
  4. Scanner fileScan;
  5.  
  6. try
  7. {
  8. fileScan = new Scanner(new File(filename));
  9.  
  10. ROWS = fileScan.nextInt(); //replace with initialization statements using values from file
  11. COLS = fileScan.nextInt();
  12. String nextChar;
  13.  
  14. board = new char[ROWS][COLS];
  15.  
  16. int currentCol = 0;
  17. int currentRow = 0;
  18.  
  19. for(int i = 0; i < ROWS - 1; i++)
  20. {
  21. for(int j = 0; j < COLS - 1; j++)
  22. {
  23. nextChar = fileScan.next();
  24. board[i][j] = nextChar.charAt(0);
  25.  
  26. if(nextChar.charAt(0) == START)
  27. {
  28. startingPoint = new Point(i,j);
  29. }
  30.  
  31. else if(nextChar.charAt(0) == END)
  32. {
  33. endingPoint = new Point(i,j);
  34. }
  35.  
  36. }
  37. }
  38.  
  39.  
  40. }
  41. catch (FileNotFoundException FNFE)
  42. {
  43. throw new FileNotFoundException("CircuitBoard-CircuitBoard");
  44. }
  45. catch (InvalidFileFormatException IFFE)
  46. {
  47. throw new InvalidFileFormatException("CircuitBoard-CircuitBoard");
  48. }
  49.  
  50. //TODO: parse the given file to populate the char[][]
  51. // throw FileNotFoundException if Scanner cannot read the file
  52. // throw InvalidFileFormatException if any formatting or parsing issues are encountered
  53.  
  54. fileScan.close();
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement