/** * WordCountTester.java * * Designed to test your WordCounter class for the assignment due 11/1/05. * * @author Jeff Ondich * @version 10/26/05 * */ import java.util.*; import java.io.*; public class WordCountTester { public static void main( String[] args ) throws FileNotFoundException { if( args.length != 1 ) { System.err.println( "Usage: java WordCountTester filename" ); return; } Scanner in = new Scanner( new File( args[0] ) ); WordCounter wordCounter = new WordCounter(); while( in.hasNext() ) { String word = cleanWord( in.next() ); if( word.length() > 0 ) { wordCounter.countWord( word ); } } System.out.println( "========== Alphabetized ==========" ); wordCounter.printReportAlphabetical(); System.out.println(); System.out.println( "========== Sorted by word counts ==========" ); wordCounter.printReportByCount(); } public static String cleanWord( String dirtyWord ) { String cleanWord = ""; int length = dirtyWord.length(); for( int k=0; k < dirtyWord.length(); k++ ) { char ch = dirtyWord.charAt( k ); if( Character.isLetter( ch ) || ch == '-' || ch == '\'' ) cleanWord = cleanWord + ch; } return cleanWord; } }