/** * Initializes a board from the given filename. * * @param filename the name of the file containing the Boggle board */ public BoggleBoard(String filename) { In in = new In(filename); M = in.readInt(); N = in.readInt(); if (M <= 0) { throw new IllegalArgumentException("number of rows must be a positive integer"); } if (N <= 0) { throw new IllegalArgumentException("number of columns must be a positive integer"); } board = new char[M][N]; for (int i = 0; i < M; i++) { for (int j = 0; j < N; j++) { String letter = in.readString().toUpperCase(); if (letter.equals("QU")) { board[i][j] = 'Q'; } else if (letter.length() != 1) { throw new IllegalArgumentException("invalid character: " + letter); } else if (ALPHABET.indexOf(letter) == -1) { throw new IllegalArgumentException("invalid character: " + letter); } else { board[i][j] = letter.charAt(0); } } } }
/** * Create a baseball division from given filename in format specified below. * * @param filename */ public BaseballElimination(String filename) { In in = new In(filename); int l = in.readInt(); wins = new int[l]; loses = new int[l]; remaining = new int[l]; games = new int[l][l]; for (int i = 0; i < l; i++) { teams.add(in.readString()); wins[i] = in.readInt(); loses[i] = in.readInt(); remaining[i] = in.readInt(); for (int j = 0; j < l; j++) { games[i][j] = in.readInt(); } } }