wordsChange);
}
else{
System.out.printf(“”Your new sentence is: %snn””
First, let’s make some changes to the existing code:
1. In the StringUtilities class add a modifier (or getter) method to retrieve the currently stored string
2. In the Lab class replace all invocations of the StringUtilities class with the Editor class
3. In the Lab class add in the new commands and their corresponding invocations
Now it’s time to modify the Editor class. This is where the bulk of the modifications are:
1. Implement the undo, redo, and reset functions
2. Implement the transformString methods so that they fill up the undo-redo-buffer while still
transforming the string.
import java.util.Scanner;
public class Lab {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
String original;
String command;
char charsChange;
String wordsChange;
char replaceThis;
String replaceThisWord;
char charsReplace;
String wordsReplace;
char withThis;
String withThisWord;
String transform;
int replaceHere;
int replaceWordHere;
System.out.printf(“nYou can perform the following operations:n” +
“Replace chars: replace all occurrences of a character another charactern”+
“Replace words: replace all occurrences of one word with another wordn”+
“Replace char: replace a specific occurrence of a charactern”+
“Replace word: replace a specific occurrence of a wordn”+
“Undo: Undo the last operationn” + “Redo: Redo the most recent undone operationn” +
“Reset: Reset to the intitial stringn”+
“Quitnn”);
System.out.printf(“Enter a string to be transformed: “);
original = scnr.nextLine();
StringUtilities m = new StringUtilities(original);
System.out.println();
do{
System.out.printf(“Enter your command: “);
command = scnr.nextLine();
//Exit command
if(command.equalsIgnoreCase(“Quit”)){
break;
}
else if(command.equalsIgnoreCase(“Replace words”)){
System.out.printf(“Enter the word to replace: “);
wordsChange = scnr.nextLine();
System.out.printf(“Enter the replacement word: “);
wordsReplace = scnr.nextLine();
if(m.transformString(wordsChange, wordsReplace) == false){
System.out.printf(“Error, “%s”” is not in the stringn””
}
else{
System.out.printf(“”Your new sentence is: %snn””