Question 4:
Question 04: (03 marks)
The interface IUtilities below is already given in Java code format, thus you can use it without creating an IUtilities .java file:
<<interface>>
IUtilities
+ countSpecial(str:String):int + sumNumberDivisible3(str:String):int
Write a class named MyUtilities, which implements the interface IUtilities. The class MyUtilities implements all methods in IUtilities as below:
+countSpecial(str: String): int: return the number of special characters includes !@#$% in the string str.
+ sumNumberDivisible3(str: String): int - return sum of digits divisible by 3 in the string str.
Hints: You can refer to the methods: contains(), charAt(), toCharArray(), valueOf() of the String class and isDigit(), digit(), getNumericValue() 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:
1. Test count Special
1. Test count Special
2. Test sumNumberDivisible3
2. Test sumNumberDivisible3
Enter Test Case No.(1/2):1
Enter Test Case No.(1/2):2
Enter a string: hello#$%123
Enter a string:hello123456
OUTPUT:3
OUTPUT:9
Zoom
+ 100%
Close