/** * A TextAnalyser object takes text (either directly as a String, or read in from a file), * and it maintains a count of the occurrences of each letter in that text. * * So e.g. analysing the text "A tap tot" would mean adding * 1 each to the counts for O and P, * 2 to the count for A, and * 3 to the count for T. * * Letters are regarded as case-insensitive (so e.g. count bs and Bs together). * Non-letter characters are ignored. * The counts for each text analysed are added together until a reset operation is invoked. * The class provides various methods for interrogating the data. * * @author Lyndon While * @version 1.1 */ public class TextAnalyser { private int letters; // the total number of letters analysed since the last reset private int[] frequencies; // the number of occurrences of each letter of the alphabet (case-insensitive) // initialise the two instance variables public TextAnalyser() { // TODO 1 } // initialise the two instance variables, and analyse the String initial public TextAnalyser(String initial) { // TODO 7 } // analyse the String s // add to each count in frequencies the number of occurrences of each letter in s, and update letters // remember that non-letter characeters must be ignored public void analyse (String s) { // TODO 2 } // analyse the contents of the file f // read in the file as a FileIO object, then analyse the contents public void analyseFile (String f) { // TODO 8 } // clear the instance variables public void reset() { // TODO 6 } // return the number of letters that have been seen since the last reset public int lettersAnalysed() { // TODO 3 return -1; } // return the number of occurrences of letter that have been seen since the last reset public int frequency (char letter) { // TODO 4 return -1; } // return the most common letter seen since the last reset // if no letters have been analysed, return '?' public char mostFrequent () { //TODO 5 return '!'; } // use Oblongs to draw a histogram of the frequencies // create an Oblong for each bar of the histogram, and arrange them appropriately on the screen public void histogram() { // TODO 9 } }