Implement the findText() method, which has two strings as parameters. The first parameter is the text to be found in the user provided sample text, and the second parameter is the user provided sample text. The method returns the number of instances a word or phrase is found in the string. In the main() method, prompt the user for a word or phrase to be found and then call findText() in the main() method.

Respuesta :

Hello, you haven't provided the programing language in which you need the code, I'll explain how to do it using Python, and you can follow the same logic to make a program in the programing language that you need.

Answer:

1. # -*- coding: utf-8 -*-

2. #Python  

3. class TextCheck:

4.      

5.     def __init__(self):

6.         self.text = input("Text to be found: ")

7.         self.sampleText = input("Sample text: ")

8.         self.findText()

9.      

10.     def findText(self):

11.         self.nTimes = self.sampleText.count(self.text)

12.      

13. FindT = TextCheck()

14. print("Number of coincidences: ", FindT.nTimes)

Explanation:

We create a class called TextCheck that has two methods, the main method (__init__) and the findText method, in the main method we ask the user for the input and after it we call findText, in findText we count the number of times that text is in sample text using a build-in method call count. To execute the program properly we instantiate the class TextCheck as FindT to then print the attribute '.nTimes' that contains the number of coincidences.

Ver imagen mateolara11