//CS1501 Spring 2006 Assignment 1: Boggle //Christine Chung //You may wish to modify this class in completing your program. //If you do so, delimit the code that you add clearly and make sure you // put your name, etc at the top of this file. import java.io.*; public class BoggleBoard { private char[][] board; //holds the letters on the boggle board private int size; //the boggle board has dimensions size x size //takes fileName and reads contents of file into //the size x size integer array board. //each integer represents ascii code corresponding //to the character in the input file. public void inputBoard(String fileName) { //make a file object File theFile = new File(fileName); BufferedReader fReader; try { //get ready to read from the file fReader = new BufferedReader(new FileReader(theFile)); //reads in the first line of the file, the size of the board String s = fReader.readLine(); size = Integer.parseInt(s); //convert it to an integer //use it to create the 2D array of characters board = new char[size][size]; //reads in integer corresponding to next character in file int asciilet = fReader.read(); //place letters from file into the board array for (int i = 0; i < size; i++) //for each row { for (int j = 0; j < size; j++) //for each column { char letter = (char) asciilet; //convert ascii number to char board[i][j] = letter; //place char on board asciilet = fReader.read(); //read next char on line (may be '\n') } asciilet = fReader.read(); //read first char of next line } } catch(Exception e) { System.out.println(e); } }//end inputBoard public void outputBoard() { //first output board size System.out.println(size); //output the letters on the board for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { System.out.print(board[i][j]); } System.out.println(); } }//end outputBoard public static void main(String [] args) { final String FILENAME = "board"; //input filename BoggleBoard bb = new BoggleBoard(); bb.inputBoard(FILENAME); //pass in the filename bb.outputBoard(); } }//end class BoardInOut