Question
Write replaceAll and undoReplaceAll methods. The GlobalReplace class has a static variable savedText shown below. public class GlobalReplace { /** Holds saved text strings from
Write replaceAll and undoReplaceAll methods.
The GlobalReplace class has a static variable savedText shown below.
public class GlobalReplace { /** Holds saved text strings from successive calls to replaceAll */ private static List |
replaceAll(text, what, sub) saves text in the savedText list, then replaces all occurrences of what in text with sub and returns modified text. Do not duplicate code from Part (a) assume that replaceOne works as specified, regardless of what you wrote in Part (a). Do not use any String methods other than length and indexOf. You may not receive full credit if you duplicate code from Part (a) or use any String methods other than length and indexOf.
Note that replaceAll proceeds from the beginning of text and replaces the occurrences of what in text in the order in which they are encountered. For example, replaceAll("AAAA", "AA", "B") should return "BB", and replaceAll("AAAA", "AAA", "B") should return "BA".
undoReplaceAll returns the original text from the last call to replaceAll. If there is no saved text, undoReplaceAll returns null.
Complete the methods replaceAll and undoReplaceAll below.
Question 1(b)
|
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started