The map will map characters to integers. Your method would be called by the following program: import java.util. Map; import java.util.List; import java.util.ArrayList; import java.util.Collections; public class Main public static void main(String () args) { Map count = MakeMap.countLetters ("hello"); List letters = new ArrayList(count.keySet ()); Collections.sort(letters); for(Character letter : letters) System.out.println("There are " + count.get (letter) + " of the letter " + letter + "); When run, this will print out the frequency of occurrence of each letter. $ java Main There are 1 of the letter 'e' There are 1 of the letter 'h' There are 2 of the letter 'l' There are 1 of the letter 'o' Note that each letter in "hello" occurs once except for the I' which occurs twice. To summarize, you write the MakeMap class with a static method countLetters(). This takes a word as a parameter. You need to create a map which maps each letter of the word to how often that letter occurs.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter9: Advanced Array Concepts
Section: Chapter Questions
Problem 19RQ
icon
Related questions
Question

Can someone help me with the following java program please

The map will map characters to integers. Your method would be called by the following program:
import java.util.Map;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
public class Main
{
public static void main(String [] args)
{
Map<Character, Integer> count =
List<Character> letters = new ArrayList<Character>(count.keySet());
Collections.sort(letters);
MakeMap.countLetters("hello");
for(Character letter : letters)
System.out.println("There are
+ count.get(letter) + " of the letter ''
+ letter + "'"');
}
}
When run, this will print out the frequency of occurrence of each letter.
$ java Main
There are 1 of the letter 'e'
There are 1 of the letter 'h'
There are 2 of the letter 'l'
There are 1 of the letter 'o'
Note that each letter in "hello" occurs once except for the 'I' which occurs twice.
To summarize, you write the MakeMap class with a static method countLetters (). This takes a word as a parameter. You need to create a map which maps each letter of the word to how often that
letter occurs.
Requested files
MakeMap.java
1 public class MakeMap
2 - {
3
// Create a static countLetters method. It should return a map of characters to integers.
4 }
Transcribed Image Text:The map will map characters to integers. Your method would be called by the following program: import java.util.Map; import java.util.List; import java.util.ArrayList; import java.util.Collections; public class Main { public static void main(String [] args) { Map<Character, Integer> count = List<Character> letters = new ArrayList<Character>(count.keySet()); Collections.sort(letters); MakeMap.countLetters("hello"); for(Character letter : letters) System.out.println("There are + count.get(letter) + " of the letter '' + letter + "'"'); } } When run, this will print out the frequency of occurrence of each letter. $ java Main There are 1 of the letter 'e' There are 1 of the letter 'h' There are 2 of the letter 'l' There are 1 of the letter 'o' Note that each letter in "hello" occurs once except for the 'I' which occurs twice. To summarize, you write the MakeMap class with a static method countLetters (). This takes a word as a parameter. You need to create a map which maps each letter of the word to how often that letter occurs. Requested files MakeMap.java 1 public class MakeMap 2 - { 3 // Create a static countLetters method. It should return a map of characters to integers. 4 }
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Top down approach design
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT