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