Question: Hey, I need help with my output - This is my pogram import java.util.Arrays; import java.util.Comparator; import java.util.Map; import java.util.Map.Entry; import java.util.Optional; import java.util.StringTokenizer; import

Hey, I need help with my output

- This is my pogram

import java.util.Arrays; import java.util.Comparator; import java.util.Map; import java.util.Map.Entry; import java.util.Optional; import java.util.StringTokenizer; import java.util.stream.Collectors; /** * This program demonstrates a solution to the Miscellaneous string operations * exercise. * */ public class MiscellaneousStringOperations { static class StringOperations { public static int wordCount(String phrase) { StringTokenizer strTok = new StringTokenizer(phrase); return strTok.countTokens(); } public static String mostFrequent(String sentence) { Comparator> byValue = (entry1, entry2) -> entry1 .getValue().compareTo(entry2.getValue()); // group existing chars together Map frequentChars = Arrays.stream( sentence.toLowerCase().split("")).collect( Collectors.groupingBy(c -> c, Collectors.counting())); // order highest to lowest Optional> val = frequentChars.entrySet() .stream().sorted(byValue.reversed()).findFirst(); return val.get().getKey(); } public static String replaceSubString(String original, String findString, String replaceString) { // If string to find and the replace string are the same then return // original b/c there is nothing to replace if (findString.equals(replaceString)) { return original; } // Make a StringBuffer object for original. StringBuffer modifiedString = new StringBuffer(original); // Find the first occurrence of findstring. int index = modifiedString.indexOf(findString); while (index != -1) { // Replace this occurrence of the substring. modifiedString.replace(index, (index + findString.length()), replaceString); // Find the next occurrence of findString. index = modifiedString.indexOf(findString); } // Return the modified string. return modifiedString.toString(); } public static String arrayToString(char[] array) { String newString = String.valueOf(array); return newString; } } public static void main(String[] args) { String phrase = "the dog jumped over the fence"; // Number of words in a string System.out.println("Number of words in \"" + phrase + "\" is " + StringOperations.wordCount(phrase)); // Show most frequent char System.out.println("Most frequently occurring character: " + StringOperations.mostFrequent(phrase)); // Replace string System.out.println("Modified phrase replacing the with that: " + StringOperations.replaceSubString(phrase, "the", "that")); // Convert an array to a string and display it. String arrayToString = StringOperations.arrayToString(phrase .toCharArray()); System.out.println("Converted arrayToString: " + arrayToString); } }

This is how output must look like;

Hey, I need help with my output - This is my pogram

Please do Project #12, p. 617 from the programming Challenges to Ch. 09. If you run it with string "the dog jumped over the fence" and character array 'H, 'o', 'w'," 'n', 'o', 'w','', b, r, 'o', 'w', 'n',", 'c', 'o', 'w' your output may look like CA C:IPROGRA-1XINOXS 1AJCREAT-21GE2001. exe Number of words in "the dog jumped over the fence" is 6 Most frequently occuring character e that dog jumped over that fence How now brown coW P .. ._ ress any key to continue Please do Project #12, p. 617 from the programming Challenges to Ch. 09. If you run it with string "the dog jumped over the fence" and character array 'H, 'o', 'w'," 'n', 'o', 'w','', b, r, 'o', 'w', 'n',", 'c', 'o', 'w' your output may look like CA C:IPROGRA-1XINOXS 1AJCREAT-21GE2001. exe Number of words in "the dog jumped over the fence" is 6 Most frequently occuring character e that dog jumped over that fence How now brown coW P .. ._ ress any key to continue

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!