"You may assume that the messages are written in lower-case letters. The frequency table has 30-lines, where each line c

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

"You may assume that the messages are written in lower-case letters. The frequency table has 30-lines, where each line c

Post by answerhappygod »

"You may assume that the messages are written in lower-case
letters. The frequency table has 30-lines, where each line contains
a letter (or a special character) followed by a space and a
positive integer (string of digits). For the simplicity purposes,
the only special characters are: `-' for space, `.' for period, `!'
for new line, and `+' for end-of-message."
Need help to incorporate this part inn code
import java.util.HashMap;
import java.util.Map;
public class HuffmanFrequencyTable {
/**
* the map for recording the key and the
frequency.
*/
private Map<Character, Integer> HuffColl;
/**
* constructor of the freq table
* @param theInput the input string
*/
public HuffmanFrequencyTable(String theInput){
HuffColl = new HashMap<Character,
Integer>();
checkandadd(theInput);
}
/**
* add each character into the freq table
* @param theInput
*/
private final void checkandadd(String theInput){
if(theInput.length() < 2) {
System.out.println("Length
of input is less than 2.");
} else {
for(int i = 0; i <
theInput.length(); i++) {
char temp =
theInput.charAt(i);

if(HuffColl.containsKey(theInput.charAt(i))){

HuffColl.put(temp, HuffColl.get(temp) + 1);
} else
{

HuffColl.put(temp, 1);
}

}
}
}
/**
* return the map object recording the table.
* @return the map represents the table.
*/
public Map<Character, Integer> getTable(){
return HuffColl;
}
}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply