Question
import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Scanner; public class MaxHomophones { private static final String FILE_NAME = cmudict-0.7a.txt; public static void main(String[] args) {
import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Scanner;
public class MaxHomophones { private static final String FILE_NAME = "cmudict-0.7a.txt"; public static void main(String[] args) { Scanner s = new Scanner(System.in); System.out.println(); int n = s.nextInt(); UALDictionary
while (n > 0 && sc.hasNextLine()) { String line = sc.nextLine(); if (line.startsWith(";;;")) { continue; } String[] parts = line.split(" "); String word = parts[0].toUpperCase(); String[] phonemes = parts[1].split(" "); String lastPhoneme = phonemes[phonemes.length - 1]; ArrayList
Need to fix this code, its supposed that the largest set of homophones in the first n lines of the pronunciation dictionary is of size k, then your program should print out k on the first line, followed by k homophones, each on a new line. If there is more than one collection of k homophones, your program should print out each group, separated by a blank line. The output should be all upper case for consistency with the pronunciation dictionary.
For example, if the input is 1000 then the correct output is 5 ABBE ABBEY ABBIE ABBY 1
2 ABIE If the input is 40000 then a correct output is 10 BURY BUERRY BERRY BERRIE BERRI BERREY BARRY(1) BARRIE(1) BARRE BAREY BAYLY BAYLEY BAYLEE BALLY(1) BALEY BAILY BAILLY BAILLIE BAILIE BAILEY It would also be correct if the order of the two groups of homophones was reversed. If the input exceeds the size of the dictionary, the output should be the same as if the input were the size of the dictionary. In this case, the output shown for the case of 1000 is throwing 1000, which is wrong. The current implementation is not producing the correct output and needs to be fixed. Please, help me by fixing the code from above. Rewrite the code if needed.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started