import java.io.FileReader; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.IOException; /* * java Grip searchString fileName * java ScrabbleCheat c--erw--l * causes all lines in file fileName containing * searchString to be put to the screen. */ public class ScrabbleCheat { public static void main(String[] args) { if(args.length < 1) { System.err.println("One Command-line argument required"); System.exit(1); } String pattern = args[0].toUpperCase(); try { BufferedReader br = new BufferedReader( new FileReader("scrabble.txt")); String line = ""; StringBuffer sb = new StringBuffer(); while( (line = br.readLine()) != null) { line = line.toUpperCase().trim(); if(matches(pattern, line)) { System.out.println(line); } } br.close(); } catch(FileNotFoundException ex) { System.err.printf("File %s not found", "scrabble.txt"); } catch(IOException ex) { ex.printStackTrace(); } } private static boolean matches(String pat, String word) { if(pat.length() != word.length()) { return false; } //r--dic--d for(int k = 0; k < word.length(); k++) { if(pat.charAt(k) != '-') { if(pat.charAt(k) != word.charAt(k)) { return false; } } } return true; } }