public class StringTester { // This program reads a text from a file, makes an array // 'words' from the individual words in the file, and // displays those words and the word count. static String [] words = new String [500]; static int nWords = 0; static String readText(String fileName) { // read an entire text file, concatenate the lines together // to form one long string and return that string. Adds an // extra blank between lines, and uses pseudoKeyboard class. pseudoKeyboard k = new pseudoKeyboard(fileName); String temp = ""; String line = k.readString(); // a single line of text while (!k.eof()) { temp = temp + line + " "; line = k.readString(); } return temp; } static String deleteExtraBlanks (String s) { // compresses s by deleting all "extra" blanks in it. That // is, it leaves every adjacent pair of words with exactly 1 // blank between them int i = s.indexOf(" "); // find a pair of blanks if (i < 0) // base case -- none there return s; else // recursive case; delete a blank return s.substring(0, i) + deleteExtraBlanks(s.substring(i+1)); } static String firstWord (String s) { // return the first word in the text s. If there is none, return "" // pass over leading blanks; look for nonblank int i = 0; while (i < s.length() && s.charAt(i) == ' ') i = i + 1; // now i is at the beginning of the word, or else there // is no next word in s. if (i >= s.length()) return ""; else // end of the word is at the blank that trails it return s.substring(i, s.indexOf(" ", i)); } static void makeArray (String s) { // build the array 'words' out of the text and set the value // of the word count variable 'nWords'. nWords = 0; // find the first word in s String t = firstWord(s); while (t!="") { // if it's there, insert it in the array 'words', words[nWords] = t; nWords = nWords + 1; // remove it from s s = s.substring(t.length() + 1); // and get the next word t = firstWord(s); } } static void displayWords () { // Display all the words in a list, one word per line. for (int i=0; i