Question: Solve in JAVA. Letter histogram Bonus : Fill in the following methods to print a histogram for which letters appear most often in the input
Solve in JAVA.
Letter histogram
Bonus: Fill in the following methods to print a histogram for which letters appear most often in the input text. Along the way, you will need to keep track of which letter (or letters) appear most often and how many times, then print the result at the end.
You can ignore all characters in the input text that are not letters from a-z or A-Z. Lowercase and uppercase letters should be counted as if they are interchangeable.
Tips:
Handle one letter at a time, proceeding from A to Z.
Implement and make use of the provided helper methods.
Keep track of the most common letters so far in a String variable, and update it as you go. You will also need to store how many times the most common letters you've seen so far appear in the text. What happens if the current letter's count is larger than the previous "best" count? What happens if it's equal to the previous best count?
Be sure to pass all the test cases and use good style. Javadoc comments and method stubs for the methods are provided. Do not modify the provided method headers.
Example input/output:
Enter the input text: The quick brown fox jumps over the lazy dog A|+ B|+ C|+ D|+ E|+++ F|+ G|+ H|++ I|+ J|+ K|+ L|+ M|+ N|+ O|++++ P|+ Q|+ R|++ S|+ T|++ U|++ V|+ W|+ X|+ Y|+ Z|+ Most common: O with 4 occurrences.

Exit Full Scre LetterHistogramjava New 10 printLetterHistogram(inputText); 12 13/** 14 Prints a histogram of the letters appearing in the given 15 16 letter(s) appearing in the text and the number of occurrences 17 18@param text The text for which to print the histogram. 19 / 20 static void printLetterHistogram(String text) 21 text, for A-Z, ignoring case. Also prints the most common TODO: Implement the method, using countOccurrences and printHistogramBar 23 24 /** 25 Counts the occurrences of a character in a String. 26 27 @param text The text in which to count the occurrences. 28 @param c The character whose occurrences to count. 29 @return The number of time the character appears in the String 30 * 31 static int countoccurrences(String text, char c) 32 TODO: Implement the method 35** 36 Prints a single bar of the histogram for one letter, in the following format: 37 38 The above bar represents 7 occurrences of the letter A. 39 letter The letter the bar represents, printed first on the line. 41@param count The width of the bar, equal to the number of +signs printed. 42 43 static void printHistogramBar(char l letter, int count) TODO: Implement the method
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
