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

Using Eclipse: Create a Java class SearchableSentence that stores a single sente

ID: 657445 • Letter: U

Question

Using Eclipse:

Create a Java class SearchableSentence that stores a single sentence and has the ability to be searched in much the same way that a word processor would search a document. Rather than finding the location of the search string as a word processor might, your class will return a count of the number of occurrences of the search string within the sentence.

Objects of this class should be able to be constructed with a single parameter containing the sentence itself. The class should contain at a minimum a method searchCount() that accepts a search string and returns the number of occurrences of that search string within the sentence. The search can be done in a case-sensitive way.

For example if the sentence searched in is The theory of Theo is that the other things are a bother. and the search string is

Explanation / Answer

public class Test { private static class SearchableSentence{ private String sentence; public SearchableSentence(String sentence){ this.sentence = sentence; } public int searchCount(String key){ if(!sentence.contains(key)) return 0; else{ int count = 0; String [] splitString = sentence.split(" "); for(int i = 0; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote