Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 savedText = new ArrayList(); ... }

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)

  • /** Saves the original text in savedText, replaces all * occurrences of what in text with sub (in order of * occurrence); returns modified text. * @param text string to be modified * @param what substring to be replaced * @param sub replacement substring * @return modified text */ public static String replaceAll(String text, String what, String sub)

  • /** Returns the text saved by the last call to replaceAll; * if there is no saved text, returns null */ public static String undoReplaceAll()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Statistical And Scientific Database Management International Working Conference Ssdbm Rome Italy June 21 23 1988 Proceedings Lncs 339

Authors: Maurizio Rafanelli ,John C. Klensin ,Per Svensson

1st Edition

354050575X, 978-3540505754

Students also viewed these Databases questions

Question

Does it exceed two pages in length?

Answered: 1 week ago

Question

Does it avoid typos and grammatical errors?

Answered: 1 week ago