Question 4:
Question 04: (03 marks)
The interface String Processor below is already given in Java code format, thus you can use it without creating a StringProcessor.java file:
<<interface>>String Processor
+ countCharacters(str:String, ch:char):int + countWordBeginByString(s1:String, s2:String):int
Write a class named SimpleStringProcessor, which implements the interface StringProcessor. The class SimpleString Processor implements all methods in String Processor as below:
countCharacters(str:String, ch:char):int - count the occurrences of character ch (not case sensitive)
in the string str. If no matching data is found, return 0
countWordBeginByString (s1:String, s2):int count the number of words in string s1 that begin with string s2(not case sensitive). Suppose that s1 is a string of words separated by a space. If no matching data is found, return 0
Hints: You can refer to the methods: startsWith(), toLowerCase() of the String class and toLowerCase() of the Character class
The Main class is provided for you in binary form. You only test your program by running the binary file. There are several test cases for you, as follows:
Zoom
+ 93%
Close