Uploaded by Dảk Công Khanh

MyString (1)

advertisement
The interface IString below is already compiled and given in byte code format, thus
you can use it without creating IString.java file.
public interface IString {
String f1(final String str, String word);
String f2(final String str, String word);
String f3(final String str);
int f4(final String str);
int f5(final String str);
String f6(final String str);
String f7(final String str);
int f8(final String str);
String f9(final String str);
}
Write a class named MyString, which implements the interface IString. The class
MyString implements methods in IString as below:
1. F1(): Return the String s, which is obtained by removing the last occurrence of a
word in str (do nothing if only one word in str).
2. F2(): Return the String s, which is obtained by replacing the last occurrence of a
word in str with the string "XX" (do nothing if only one word in str)
3. F3(): Return the string s, which is obtained by removing the second word having
maximum length in the string str (do nothing if only one maximum length word
in str)
4. F4(): Count and return number of words containing digits and having sum of
digit > 2 (word = a string without space(s) )
5. F5(): Count and return number of words containing letters and having length is
even (word = a string without space(s) )
6. F6(): Return the string s, which is obtained by removing all non-letter and nondigit characters from the string str.
7. F7(): Return the longest palindrome in the str.
8. F8(): Return summation of a given string str as the rule: sum = sum of all digits
of the first and the last numbers in str.
9. F9(): Return the string s, which is obtained by veversing the first and the last
number in the string str.
The program output might look something like:
Test (1:f1, 2:f2, 3:f3, 4:f4, 5:f5,
6:f6, 7:f7, 8:f8, 9:f9):
Test (1:f1, 2:f2, 3:f3, 4:f4, 5:f5,
6:f6, 7:f7, 8:f8, 9:f9):
Test (1:f1, 2:f2, 3:f3, 4:f4, 5:f5,
6:f6, 7:f7, 8:f8, 9:f9):
Enter TC: 1
Enter TC: 1
Enter TC: 1
Enter a string:
Enter a string:
Enter a string:
a a1 b2 c34 d6 a1 c9
a a1 b2 c34 a1 d6 c9 a1 f10
a a1 b2 c34 d6 c9
Enter a word: a1
Enter a word: a1
Enter a word: a1
OUTPUT:
OUTPUT:
OUTPUT:
a a1 b2 c34 d6 c9
a a1 b2 c34 a1 d6 c9 f10
a a1 b2 c34 d6 c9
Test (1:f1, 2:f2, 3:f3, 4:f4, 5:f5,
6:f6, 7:f7, 8:f8, 9:f9):
Test (1:f1, 2:f2, 3:f3, 4:f4, 5:f5,
6:f6, 7:f7, 8:f8, 9:f9):
Test (1:f1, 2:f2, 3:f3, 4:f4, 5:f5,
6:f6, 7:f7, 8:f8, 9:f9):
Enter TC: 2
Enter TC: 2
Enter TC: 2
Enter a string:
Enter a string:
Enter a string:
a a1 b2 c34 d6 a1 c9
a a1 b2 c34 a1 d6 c9 a1 f10
a a1 b2 c34 d6 c9
Enter a word: a1
Enter a word: a1
Enter a word: a1
OUTPUT:
OUTPUT:
OUTPUT:
a a1 b2 c34 d6 XX c9
a a1 b2 c34 a1 d6 XX c9 f10
a a1 b2 c34 d6 c9
Test (1:f1, 2:f2, 3:f3, 4:f4, 5:f5,
6:f6, 7:f7, 8:f8, 9:f9):
Test (1:f1, 2:f2, 3:f3, 4:f4, 5:f5,
6:f6, 7:f7, 8:f8, 9:f9):
Test (1:f1, 2:f2, 3:f3, 4:f4, 5:f5,
6:f6, 7:f7, 8:f8, 9:f9):
Enter TC: 3
Enter TC: 3
Enter TC: 3
Enter a string:
Enter a string:
Enter a string:
a1 aa1 aaa1 b2 bb2 bbb2 c3
a1 aa1 aaa1 b2 bb2 bbb2 c3 ccc3
a1 aa1 aaa1 b2 bb2 c3
OUTPUT:
OUTPUT:
OUTPUT:
a1 aa1 aaa1 b2 bb2 c3
a1 aa1 aaa1 b2 bb2 c3 ccc3
a1 aa1 aaa1 b2 bb2 c3
Test (1:f1, 2:f2, 3:f3, 4:f4, 5:f5,
6:f6, 7:f7, 8:f8, 9:f9):
Test (1:f1, 2:f2, 3:f3, 4:f4, 5:f5, 6:f6,
7:f7, 8:f8, 9:f9):
Test (1:f1, 2:f2, 3:f3, 4:f4, 5:f5,
6:f6, 7:f7, 8:f8, 9:f9):
Enter TC: 4
Enter TC: 5
Enter TC: 6
Enter a string:
Enter a string:
Enter a string:
a 111 b3 20 23 c4 234
abcd 111 bbaa2 20 aba c4a3 propro
abc $123@ !abce %2w*?
OUTPUT:
OUTPUT:
OUTPUT:
3
2
abc123abce2w
Test (1:f1, 2:f2, 3:f3, 4:f4, 5:f5, 6:f6, 7:f7, 8:f8, 9:f9):
Enter TC: 7
Enter a string:
ab 1221 uv 12321 xy abc7cba ba aba
OUTPUT:
abc7cba
Test (1:f1, 2:f2, 3:f3, 4:f4, 5:f5, 6:f6, 7:f7, 8:f8, 9:f9):
Enter TC: 8
Enter a string:
1a 123 ab 23 abc 10
OUTPUT:
7
Test (1:f1, 2:f2, 3:f3, 4:f4, 5:f5, 6:f6, 7:f7, 8:f8, 9:f9):
Enter TC: 9
Enter a string:
1a 123 ab 145 cd 201
OUTPUT:
321 102
Download