Question: Write a program that will read a line of text that ends with a period, which serves as a sentinel value . Display all the

Write a program that will read a line of text that ends with a period, which serves as a sentinel value . Display all the letters that occur in the text, one per line and in alphabetical order, along with the number of times each letter occurs in the text. Use an array of base type int of length 26, so that the ele- ment at index 0 contains the number of as, the element at index 1 contains the number of bs, and so forth. Allow both uppercase and lowercase letters as input, but treat uppercase and lowercase versions of the same letter as being equal .(Hints:Use one of the methods to UpperCase or to LowerCase in the wrapper class Character , described in chapter 6. You will find it helpful to define a method that takes a character as an argument and returns an int value that is the correct index for that character . For example, the argument 'a' results in 0 as the return value , the argument 'b' gives 1 as the return value , and so on. note that you can use a type cast, such as (int ) letter, to change a char to an int . Of course, this will not get the number you want, but if you subtract (int )'a', you will then get the right index.) Allow the user to repeat this task until the user says she or he is through.

SAMPLE RUN #4: java LetterFreq

Interactive Session Standard Input Standard Error (empty) Standard Output Hide Invisibles

Highlight: NoneStandard Input OnlyPrompts OnlyStandard Output w/o PromptsFull Standard OutputAllShow Highlighted Only

Enterasentenceendingwithaperiodoranythingnotendinginaperiodtoend:!If youbuiltyourlettercounterproperlyitwillnotcountanythingbutproperletters.  TheletterAoccurred1timesinthesentence. TheletterBoccurred2timesinthesentence. TheletterCoccurred2timesinthesentence. TheletterEoccurred7timesinthesentence. TheletterFoccurred1timesinthesentence. TheletterGoccurred1timesinthesentence. TheletterHoccurred1timesinthesentence. TheletterIoccurred5timesinthesentence. TheletterLoccurred6timesinthesentence. TheletterNoccurred5timesinthesentence. TheletterOoccurred7timesinthesentence. TheletterPoccurred4timesinthesentence. TheletterRoccurred8timesinthesentence. TheletterSoccurred1timesinthesentence. TheletterToccurred11timesinthesentence. TheletterUoccurred6timesinthesentence. TheletterWoccurred1timesinthesentence. TheletterYoccurred4timesinthesentence. Enterasentenceendingwithaperiodoranythingnotendinginaperiodtoend:AlsOTheDegReeOFcaptilizationSHOULDNOTAFFECTYOURCOUNTERinanywayshapeorform. TheletterAoccurred7timesinthesentence. TheletterCoccurred3timesinthesentence. TheletterDoccurred2timesinthesentence. TheletterEoccurred7timesinthesentence. TheletterFoccurred4timesinthesentence. TheletterGoccurred1timesinthesentence. TheletterHoccurred3timesinthesentence. TheletterIoccurred4timesinthesentence. TheletterLoccurred3timesinthesentence. TheletterMoccurred1timesinthesentence. TheletterNoccurred5timesinthesentence. TheletterOoccurred9timesinthesentence. TheletterPoccurred2timesinthesentence. TheletterRoccurred5timesinthesentence. TheletterSoccurred3timesinthesentence. TheletterToccurred6timesinthesentence. TheletterUoccurred3timesinthesentence. TheletterWoccurred1timesinthesentence. TheletterYoccurred3timesinthesentence. TheletterZoccurred1timesinthesentence. Enterasentenceendingwithaperiodoranythingnotendinginaperiodtoend:Multiplesentencesononelinearefine.Aslongasthelineendswithaperiod. TheletterAoccurred4timesinthesentence. TheletterCoccurred1timesinthesentence. TheletterDoccurred2timesinthesentence. TheletterEoccurred12timesinthesentence. TheletterFoccurred1timesinthesentence. TheletterGoccurred1timesinthesentence. TheletterHoccurred2timesinthesentence. TheletterIoccurred6timesinthesentence. TheletterLoccurred5timesinthesentence. TheletterMoccurred1timesinthesentence. TheletterNoccurred9timesinthesentence. TheletterOoccurred4timesinthesentence. TheletterPoccurred2timesinthesentence. TheletterRoccurred2timesinthesentence. TheletterSoccurred5timesinthesentence. TheletterToccurred4timesinthesentence. TheletterUoccurred1timesinthesentence. TheletterWoccurred1timesinthesentence. Enterasentenceendingwithaperiodoranythingnotendinginaperiodtoend:aaaaabbbbbtttttuuuuuuuuuu. TheletterAoccurred5timesinthesentence. TheletterBoccurred5timesinthesentence. TheletterToccurred5timesinthesentence. TheletterUoccurred10timesinthesentence. Enterasentenceendingwithaperiodoranythingnotendinginaperiodtoend:Goodbye  

Question:

I got the basic code correct, but I'm having trouble with all the prompts. I can't seem to get the output I need. What is your solution?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!