In this assignment, you will write a Java program that counts the 26 letter frequencies for a given string. You may name your Java file name as LetterCounter ArrayApp.java, and write methods that use arrays to store the frequencies. The detailed descriptions are as follows: • Method 1: countLetters() /* * Return an array of 26 letters’ frequencies for a given string * * Note: You only need count the frequency for 26 letters * i.e., "abcdefghijklmnopqrstuvwxyz". * you should count both uppercase and lower case letters */ public static int [] countLetters(String str) { // your work } • Method 2: printLetterFreq() /* * Print the letters, their frequencies, and frequency representations * @countArray: an array of 26 letters frequencies in an alphabetic order * * Note: Only print those frequencies > 0. */ public static void printLetterFreq(int [] countArray) { // your work } 1 • Method 3: numToStar(int num) /* * Return a string with a number of stars (*) corresponding to the input * "num", For instance, if num = 5, then you should return "*****" * * Note: This method will be invoked in the method of printLetterFreq() */ public static String numToStar(int num) { // your work here } • Method 4: mostFreqLetter(). /* * Find the most frequent letter in all 26 letter frequencies. * @countArray: an array of 26 letters frequencies in an alphabetic order * * Note: If there are more than one letters with highest frequencies, * then return the first most frequent letter. */ public static char mostFreqLetter(int [] countArray) { // your work here } In your main() method, you apply these methods on each of four strings stored in a file inputstring.txt, and display the letter frequencies for each string(See a sample screenshot of the first input string). Particularly, you should do the following • Declare a string variable, and initialize it using the first string from inputstring.txt (Hint: Just copy the string from the file and paste it in your program); • Compute the 26 letter frequencies using the method of counteLetters(); • Display the 26 letter frequencies using the method of printLetterFreq(); • Display the most frequent letter using the method of mostFreqLetter(); • Repeat the above steps on the second, third and fourth string from the input file. 2 2 Additional Requirements 1. Your program should have good style (indentation, whitespace, comments, vertical alignment, ...). 2. Your program outputs should be neat (See the screenshot of the first one shown in Figure 1). Particularly: • Only print out letters with some numbers of frequencies. In other words, don’t print out the letters with zero frequencies. • The letter frequencies should be placed inside the parenthesis.
In this assignment, you will write a Java program that counts the 26 letter frequencies for a given string. You may name your Java file name as LetterCounter ArrayApp.java, and write methods that use arrays to store the frequencies. The detailed descriptions are as follows: • Method 1: countLetters() /* * Return an array of 26 letters’ frequencies for a given string * * Note: You only need count the frequency for 26 letters * i.e., "abcdefghijklmnopqrstuvwxyz". * you should count both uppercase and lower case letters */ public static int [] countLetters(String str) { // your work } • Method 2: printLetterFreq() /* * Print the letters, their frequencies, and frequency representations * @countArray: an array of 26 letters frequencies in an alphabetic order * * Note: Only print those frequencies > 0. */ public static void printLetterFreq(int [] countArray) { // your work } 1 • Method 3: numToStar(int num) /* * Return a string with a number of stars (*) corresponding to the input * "num", For instance, if num = 5, then you should return "*****" * * Note: This method will be invoked in the method of printLetterFreq() */ public static String numToStar(int num) { // your work here } • Method 4: mostFreqLetter(). /* * Find the most frequent letter in all 26 letter frequencies. * @countArray: an array of 26 letters frequencies in an alphabetic order * * Note: If there are more than one letters with highest frequencies, * then return the first most frequent letter. */ public static char mostFreqLetter(int [] countArray) { // your work here } In your main() method, you apply these methods on each of four strings stored in a file inputstring.txt, and display the letter frequencies for each string(See a sample screenshot of the first input string). Particularly, you should do the following • Declare a string variable, and initialize it using the first string from inputstring.txt (Hint: Just copy the string from the file and paste it in your program); • Compute the 26 letter frequencies using the method of counteLetters(); • Display the 26 letter frequencies using the method of printLetterFreq(); • Display the most frequent letter using the method of mostFreqLetter(); • Repeat the above steps on the second, third and fourth string from the input file. 2 2 Additional Requirements 1. Your program should have good style (indentation, whitespace, comments, vertical alignment, ...). 2. Your program outputs should be neat (See the screenshot of the first one shown in Figure 1). Particularly: • Only print out letters with some numbers of frequencies. In other words, don’t print out the letters with zero frequencies. • The letter frequencies should be placed inside the parenthesis.
Code:
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 7 images