Question: Exercise 5.9.4: Converting Binary to Decimal Sandbox My Section Practice + Resume Yanhua Liu New + 5.8.4 Word Counts Submit + Continue Save Output Test

Exercise 5.9.4: Converting Binary to Decimal

Exercise 5.9.4: Converting Binary to Decimal Sandbox My Section Practice + Resume

Sandbox My Section Practice + Resume Yanhua Liu New + 5.8.4 Word Counts Submit + Continue Save Output Test Cases Docs Assignment Grade More 1 . import java. util.*; WordCounts.java 10 points Status: Not Submitted public class WordCounts extends ConsoleProgram In this program you will ask the user for a String, and then output the count of every word in that String in 5 public void run() alphabetical order. You'll need to use a HashMap to do this. 6 - / / Start here! For example if the user entered: 8 a Hello hello world 10 11 This method takes a HashMap of word counts and prints out You'd print out 12 * each word and it's associated count in alphabetical order. hello: 2 13 14 @param wordCount The HashMap mapping words to each word's frequency count world: 1 15 16 private void printSortedHashMap (HashMap wordCount) { Since the word hello appeared twice and the word world appeared once. 17 // Sort all the keys (words) in the HashMap 18 Object keys = wordCount . keySet() . toArray (); HINT: 19 Arrays . sort (keys) ; 20 Use the provided printSortedHashMap method to print out the HashMap in alphabetical order. 21 // Print out each word and it's associated count 22 - for (Object word : keys) { 23 int val = wordCount. get(word) ; 24 System. out. printIn(word + ": " + val); 25 26 27

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 Programming Questions!