Question

In: Computer Science

In Java 1) A homophone is one of two or more words that are pronounced alike...

In Java

1) A homophone is one of two or more words that are pronounced alike but are different in meaning or spelling; for example, the words “two", “too", and “to". Write a Java program that uses HashMap to find the most words that has the same homophones and return the count of the number of words. 2) Implement insertionSort. 3) Given any integer, print an English phrase that describes the integer (e.g. “One Thousand, Two Hundred Thirty Four”). An ArrayList or LinkedList must be used in your program.

Solutions

Expert Solution


import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Comparator;
import java.util.SortedSet;
import java.util.TreeSet;
public class MostHomophones {
public static void main(String[] args) throws FileNotFoundException {
MostHomophones ex = new MostHomophones();
}


ArrayList <String> value = new ArrayList<>();
HashMap <String, ArrayList<String>> lhm = new HashMap();
HashMap <String, ArrayList<String>> Entry = new HashMap();


public MostHomophones() throws FileNotFoundException {
Scanner input = new Scanner(new FileReader("cmudict.0.7a.txt"));

while(input.hasNext()) {
String s = input.nextLine();
value.add(s);
String[] line = s.split(" ");
System.out.println(line[0]);
  
String key = s.substring(line[0].length() + 1 , s.length());
if(lhm.containsKey(key)){
ArrayList<String> value = lhm.get(key);
value.add(line[0]);
lhm.put(key,value);
}
else{

ArrayList<String> value = new ArrayList<String>(Collections.singleton(line[0]));
lhm.put(key,value);
}

Map.Entry<String, Integer> maxEntry = null;

  

}
int largest = 0;
ArrayList <String> wordList = new ArrayList<>();
for(Map.Entry<String, ArrayList<String>> ent : lhm.entrySet()){
largest = (ent.getValue().size() > largest) ? ent.getValue().size() : largest;
wordList = (ent.getValue().size() > largest) ? ent.getValue() : wordList;
}
System.out.println("The most frequent is " + largest + " times.");
System.out.println("The words are " + wordList);

input.close();

}


}


Related Solutions

In JAVA Make a separate post (50 words or more for each) on two of the...
In JAVA Make a separate post (50 words or more for each) on two of the following topics before the Initial Post due date. Topics (choose two, separate post for each) Before taking this course, how much exposure did you have to Exceptions? Have you used Java Error classes in the past? Explain how you used them. Are Checked Exception easy or hard to understand? How are they hard to figure out? What helps you understand how they work so...
JAVA JAVA JAVA JAVA, How to determine if there is more than one number that appeared...
JAVA JAVA JAVA JAVA, How to determine if there is more than one number that appeared the X amount of times. (For example there are 3 numbers which occured 50 times so I want the output to show which 3 numbers occured 50 times) This is the code import java.util.Random; public class MostLeastOccurring { public static void main(String[] args) { Random random = new Random(); int x = 1000; int[] array = new int[x]; for (int i = 0; i...
in two hundred words Name and discuss one or more of the opportunities in HIM. Be...
in two hundred words Name and discuss one or more of the opportunities in HIM. Be sure to address the educational and experience requirements.
1. The crowing out effect of government spending will be less pronounced if Select one: a....
1. The crowing out effect of government spending will be less pronounced if Select one: a. government borrows mostly in the international financial markets b. consumption spending is more sensitive to changes in the interest rate c. none of the answers is correct d. equilibrium GDP is further below potential GDP 2. Because of lower investment in basic research, the technological change in Australian economy slows down. As a result Select one: a. the economy will move down along the...
write a thesis Ottomans, the Safavids, and Mughals more alike or different
write a thesis Ottomans, the Safavids, and Mughals more alike or different
1 A)What are the two different categories of cell types? How are they alike? How are...
1 A)What are the two different categories of cell types? How are they alike? How are they different? 1 B)If you are a bacterial biologist and you want to develop an antibiotic that will kill bacterial cells but not harm humans, what would you look for as a place to focus?
1.The terms H II and H2 are both pronounced “H two.” What is the difference in...
1.The terms H II and H2 are both pronounced “H two.” What is the difference in meaning of those two terms? Can there be such a thing as H III? 2. Why do nebulae near hot stars look red? Why do dust clouds near stars usually look blue? 3. Describe the characteristics of the various kinds of interstellar gas (HII regions, neutral hydrogen clouds, ultra-hot gas clouds, and molecular clouds). 4. Describe how the 21-cm line of hydrogen is formed....
Write a program in JAVA that takes in two words, and then it recursively determines if...
Write a program in JAVA that takes in two words, and then it recursively determines if the letters of the first word are contained, in any order, in the second word. If the size of the first word is larger than the second then it should automatically return false. Also if both strings are empty then return true. YOU MAY NOT(!!!!!!!!!!): Use any iterative loops. In other words, no for-loops, no while-loops, no do-while-loops, no for-each loops. Use the string...
Why is photochemical smog more pronounced in the early morning hours? (use reactions as part of...
Why is photochemical smog more pronounced in the early morning hours? (use reactions as part of the answer)
in 300 hundred words or more, please write, in your own words, about one of the...
in 300 hundred words or more, please write, in your own words, about one of the entities that establish the rules accountants must follow when preparing financial reports. they include, but are not limited to, the Financial Accounting Standards Board (FASB), International Accounting Standards Board (IASB), and the Security Exchange Commission (SEC). please also state your opinion wether the mission of the organization you are writing on helps to provide guidance to aacountants or is repetitive of other standard-making bodies....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT