Question
Write a program that analyzes text written in the console by counting the number of times each of the 26 letters in the alphabet occurs.
Write a program that analyzes text written in the console by counting the number of times each of the 26 letters in the alphabet occurs. Uppercase and lowercase letters should be counted together (for example, both A and a should count as an A). Any characters that are not letters should be ignored. You must prompt the user to enter the text to be analyzed. Then, for any letter that appeared at least once in the text, print out the number of times it appeared (and do so in alphabetical order). An effective way to count characters is to read from the console string-by-string, and loop through all of the characters of each of these strings. Similar to Problem a, the hasNext() method of the scanner will be useful, and when testing in Eclipse, press enter and then, once on the empty line, press CTRL-D when you are done typing the text. You must use an array to keep track of how many times each letter is seen in the text. The array should have 26 elements (one for each letter in the alphabet). Index 0 should be used to track the number of As in the file, index 1 to track the Bs, index 2 to track the Cs, etc., up to index 25 for the Zs. You could use a massive if/else block, but the whole reason to use arrays is to make your programs easier. So, instead, think about how to convert each character you read into the correct index and then increment that value in the array. For example, if you read an A, then you should increment the value in index 0. Specifically, you will need to determine if the character is an uppercase letter (between A and Z), a lowercase letter (between a and z), or something else. If it is a letter, convert it into the appropriate index. Recall that characters and integers are interchangeable via the ASCII table conversion1. Consider this example to help get you started: char input = 'z'; int index = input - 'a'; // index equals 25, as 'z' is 122 and 'a' is 97 You have been supplied JUnit tests for several example input texts, including an empty text, one with no letters, upper/lower/mixed case letters, and Hello World.
I know this is posted already but its must pass these tests! The code must run these inputs and result in these outputs. input: , output: (nothing) input: 1 2 3 output: (nothing) input: Hello World! output: D: 1 E: 1 H: 1 L: 3 O: 2 R: 1 W: 1 input: a b B C c C d D D d E e E e E output: A: 1 B: 2 C: 3 D: 4 E: 5 input: A B B C C C D D D D E E E E E output: A: 1 B: 2 C: 3 D: 4 E: 5 input: a b b c c c d d d d e e e e e output: A: 1 B: 2 C: 3 D: 4 E: 5
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started