Question: Java Create a class called Sentence The Sentence class will determine in a phrase (substring) is within a sentence object, for example ing is contain
Java
Create a class called Sentence
The Sentence class will determine in a phrase (substring) is within a sentence object, for example "ing" is contain in the sentence "The boy is running".
Instance variable - String that represents a sentence.
Constructor - single parameters that sets the instance variable
Methods
Accessor and mutator for the sentence
find method
takes in a String parameter that represents the target substring, (what we are looking)
returns true if the substring occurs in the sentence, false if it doesn't occur.
Must use recursion and use this algorithm
If sentence starts with the target substring return true
If not, test the rest of the sentence recursively.
Remember to include stopping base case(s).
Enhancement (Optional) create an indexOf method
takes in a String parameter that represents the target substring, (what we are looking)
returns the index in the Sentence of the first occurence of the target substring or -1 if not found
Must use recursion
One approach is to use a recursive helper method
The purpose of a "helper" recursive methods is,in general, to hide the counting of something. They usually have (at least) one additional parameter that somehow describes how far the recursion has already proceeded or how far it still has to proceed. In our case the helper method extra parameter would be where the new string starts, and that parameter would be returned when the substring is found.
Create a SentenceTester class
Create a Sentence object.
Test several phrase including several with match throughout the sentence and some that do not match.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
