i need help with filling incorrect each line that is indicat
i need help with filling in/correct each line that is indicated by a comment with a number
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
public class WordTypeCount
{
public static void main(String[] args)
{
//#1 create HashMap called myMap to store String keys and Integer values
createMap(myMap);
displayMap(myMap);
}
// create map from user input
private static void createMap(Map<Character, Integer> myMap)
{
Scanner scanner = new Scanner(System.in); // create scanner
System.out.println(\"Enter a string:\"); // prompt for user input
String input = scanner.nextLine();
//#2 convert to lowercase and remove all non-letters
// use toLowerCase and replaceAll
// processing input text
for (char letter : input.toCharArray())
{
// write if conditional using containsKey()- if the map contains the word
{
//#3 use map.get to get current count
//#4 use map.put to put it at the NEXT position
}
else
map.put(letter, 1); // add new word with a count of 1 to map
}
}
// display map content
private static void displayMap(Map<Character, Integer> map)
{
Set<Character> keys = map.keySet(); // get keys
// sort keys using a TreeSet
//#5 Create a TreeSet of Characters called sortedKeys
System.out.printf(\"%nMap contains:\ Key\\t\\tValue%n\");
// generate output for each key in map
for (char key : sortedKeys)
//#6 Print the keys using map.get
//#7 Use isEmpty to tell me whether the map is empty
}
} // end class WordTypeCount
Solution
Please find the required program along with its output. Please see the comments against each line to understand the step.
------------------------
OUTPUT:
Enter a string:
 Hi hello how are you
Map contains:
 Key       Value
 a : 1
 e : 2
 h : 3
 i : 1
 l : 2
 o : 3
 r : 1
 u : 1
 w : 1
 y : 1


