Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

ava expert please help me JAVA program below? Here is the requirement: Please sh

ID: 3830626 • Letter: A

Question

ava expert please help me JAVA program below? Here is the requirement:

Please show your program's output as example above

---------CountOccurrenceOfWords.java---------

import java.util.*;

public class CountOccurrenceOfWords {
public static void main(String[] args) {
// Set text in a string
String text = "Good morning. Have a good class. " +
"Have a good visit. Have fun!";

// Create a TreeMap to hold words as key and count as value
Map<String, Integer> map = new TreeMap<String, Integer>();

String[] words = text.split("[ .,;:!?(){}]");
for (int i = 0; i < words.length; i++) {
String key = words[i].toLowerCase();

if (key.length() > 0) {
if (!map.containsKey(key)) {
map.put(key, 1);
}
else {
int value = map.get(key);
value++;
map.put(key, value);
}
}
}

// Get all entries into a set
Set<Map.Entry<String, Integer>> entrySet = map.entrySet();

// Get key and value from each entry
for (Map.Entry<String, Integer> entry: entrySet)
System.out.println(entry.getKey() + " " + entry.getValue());
}
}

Frequent Words Modify CountOccurrenceOfWords java. Your program should take a text file name as a command line argument. It should read the file and print the number of times the most-used word appears and, in ascending order, the words that occur most frequently. Ignore case when processing the words in the file. Your program may ignore punctuation. For example, if the file contained Sophie Sally and Jack were dachshunds Dachshunds are the best dogs and all dogs are better than cats The program's output should be Words that appear 2 times: and are dachshunds dogs

Explanation / Answer

CountOccurrenceOfWords.java

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeMap;

public class CountOccurrenceOfWords {
   public static void main(String[] args) throws FileNotFoundException {
       Scanner scan = new Scanner(new File(args[0]));
       // Create a TreeMap to hold words as key and count as value
       Map<String, Integer> map = new TreeMap<String, Integer>();

       while (scan.hasNext()) {
           String key = scan.next();
           if (!map.containsKey(key.toLowerCase())) {
               map.put(key.toLowerCase(), 1);
           } else {
               int value = map.get(key.toLowerCase());
               value++;
               map.put(key.toLowerCase(), value);
           }
       }
       // Get all entries into a set
       Set<Map.Entry<String, Integer>> entrySet = map.entrySet();
       int maxTimes = 0;
       // Get key and value from each entry
       for (Map.Entry<String, Integer> entry : entrySet) {
           if(maxTimes < entry.getValue()){
               maxTimes=entry.getValue();
           }
       }
       System.out.print("Words that appear "+maxTimes+" times: ");
       for (Map.Entry<String, Integer> entry : entrySet) {
           if(entry.getValue() == maxTimes)
           System.out.print(entry.getKey()+" ");
       }
       System.out.println();
   }
}

Output:

Words that appear 2 times: and are dachshunds dogs