Practise Problems for Labtest 4
10/11/11 09:41 Filed in: Labs
Practice Questions for Labtest 04 (Set 1 of 2)
in addition to Ch 6 RQ's and Ch 6 exercises
Labtest 04 takes place Nov 17, 18, 21
Frequency
Given a string and a single target character, derive the frequency of the character within the string. You should be able to this using:
• Iteration and toCharArry()
• Iteration and charAt
• Iteration and substring
• replaceAll and length in combination
Given a string and a n-character long target string, derive the frequency of the
target string within the string. You should be able to this using:
• Iteration and substring
• replaceAll
Matching
Given a description of a domain of acceptable strings (and unacceptable strings), construct a test to see whether a given string is acceptable. You should be able to this using:
• if-elseif-else block and string equality testing
• matches and regular expressions
Implement a case-insensitive check whether two strings are the same
Substitution/Removal
Given a string, a single target character and a replacement character, implement character substitution. You should be able to this using:
• Iteration, condition testing, and string concatenation
• Iteration, condition testing, and a string buffer
• replaceAll
• all of the above, but with character removal rather than substitution
Given a string, a target string and a replacement string, implement substring substitution. You should be able to this using:
• Iteration, condition testing, and string concatenation
• Iteration, condition testing, and a string buffer
• Iteration, indexOf, and string concatenation
• Iteration, indexOf, and a StringBuffer
• replaceAll
• all of the above, but with substring removal rather than substitution
Given a description of a domain of acceptable strings (and unacceptable strings), implement code to remove all matching substrings
• replaceAll
Modification/Concatenation
Modification of a string in a position-sensitive manner, such as:
– user enters first and family name, separated by a space. want to insert the middle name into the string
– use String, use substring to split, then use concatenation and reassignment
– use StringBuffer, use insert
Given a string composed using string concatenation, accomplish the same result using a StringBuffer object
in addition to Ch 6 RQ's and Ch 6 exercises
Labtest 04 takes place Nov 17, 18, 21
Frequency
Given a string and a single target character, derive the frequency of the character within the string. You should be able to this using:
• Iteration and toCharArry()
• Iteration and charAt
• Iteration and substring
• replaceAll and length in combination
Given a string and a n-character long target string, derive the frequency of the
target string within the string. You should be able to this using:
• Iteration and substring
• replaceAll
Matching
Given a description of a domain of acceptable strings (and unacceptable strings), construct a test to see whether a given string is acceptable. You should be able to this using:
• if-elseif-else block and string equality testing
• matches and regular expressions
Implement a case-insensitive check whether two strings are the same
Substitution/Removal
Given a string, a single target character and a replacement character, implement character substitution. You should be able to this using:
• Iteration, condition testing, and string concatenation
• Iteration, condition testing, and a string buffer
• replaceAll
• all of the above, but with character removal rather than substitution
Given a string, a target string and a replacement string, implement substring substitution. You should be able to this using:
• Iteration, condition testing, and string concatenation
• Iteration, condition testing, and a string buffer
• Iteration, indexOf, and string concatenation
• Iteration, indexOf, and a StringBuffer
• replaceAll
• all of the above, but with substring removal rather than substitution
Given a description of a domain of acceptable strings (and unacceptable strings), implement code to remove all matching substrings
• replaceAll
Modification/Concatenation
Modification of a string in a position-sensitive manner, such as:
– user enters first and family name, separated by a space. want to insert the middle name into the string
– use String, use substring to split, then use concatenation and reassignment
– use StringBuffer, use insert
Given a string composed using string concatenation, accomplish the same result using a StringBuffer object