import java.util.*; public class Scanner { Disk in, out; Set64 board = new Set64(); String fileName; /** * @param filename the filename of the input text file containing the scanner array */ public Scanner(String filename){ in = new Disk(filename, "in"); fileName = filename; } protected String newWord(String s){ return s; } protected String lineHandler(String s){ StringTokenizer toks = new StringTokenizer(s); String result = ""; while (toks.hasMoreTokens()){ result += newWord(toks.nextToken()) + " "; } return result; } /** * copies the scanner array to an output text file, unmodified * @param filename the filename of the new text file to which the scanner array will be copied */ public void print(String filename){ in = new Disk(fileName, "in"); out = new Disk(filename, "out"); String line = in.readLine(); while(line != null){ out.out.println(lineHandler(line)); line =in.readLine(); } out.out.close(); } /** * prints to the specified file an array with the same dimensions as the scanner array, preserving the elements of each maximal horizontal run in the scanner array. All other array elements are replaced by ‘-’ characters * @param filename the filename of the new text file to which the scanner showing the horizontal runs will be printed */ public void maxHRun(String filename){ in = new Disk(fileName, "in"); String line = in.readLine(); line.trim(); while(line != null){ if (line.length() > 0){ String[] rowArray = line.split(" "); Integer [] columns = new Integer[rowArray.length]; for(int i=0;i= currentLongestRun ) { currentLongestRun = j-i; i=j-1; } break; } } if (j == (rowArr.length)){ if ( (j - i) >= currentLongestRun ) { currentLongestRun = j-i; i = j-1; } } } } board.reset(); while(board.hasNext()){ Integer[] rowArr = (Integer[]) board.next(); for(int i=0;i 0){ String[] rowArray = line.split(" "); Integer [] columns = new Integer[rowArray.length]; for(int i=0;i= currentLongestRun ) { currentLongestRun = j-i; i=j-1; } break; } } if (j == (rowArr.length)){ if ( (j - i) >= currentLongestRun ) { currentLongestRun = j-i; i = j-1; } } } } board.reset(); while(board.hasNext()){ Integer[] rowArr = (Integer[]) board.next(); for(int i=0;i 0){ //String[] rowArray = line.split(" "); //Integer [] columns = new Integer[rowArray.length]; //for(int i=0;i 0){ counter++; } line = in.readLine(); } System.out.println(counter); return counter; } public int columns(){ in = new Disk(fileName,"in"); String line = in.readLine(); line.trim(); String[] arr = line.split(" "); System.out.println(arr.length); return arr.length; } public boolean equals(Scanner scan){ if(this.shapeEquals(scan) == false){ System.out.println("false"); return false; } else{ in = new Disk(fileName,"in"); String thisLine = in.readLine(); thisLine.trim(); String scanLine = scan.in.readLine(); scanLine.trim(); while(thisLine != null){ if(thisLine.length() > 0){ if(thisLine != scanLine){ System.out.println("false"); return false; } } thisLine = in.readLine(); scanLine = scan.in.readLine(); } System.out.println("true"); return true; } } public static void main(String [] args){ Scanner scan = new Scanner("in3.txt"); Scanner scan2= new Scanner("in2.txt"); Scanner scan3= new Scanner("in3.txt"); scan.equals(scan2); scan.equals(scan3); //scan.print("out.txt"); //scan.maxHRun("out.txt"); //scan.rows(); //scan.columns(); } }