Create a java text processing program that allows users to manipulate text in various ways. Your program should consist of multiple classes to organize functionality effectively. Requirements: 1.Implement a TextProcessor class responsible for managing text manipulation operations. 2.Implement a Main class to handle user input and interaction. 3.Allow users to perform the following operations: Append text to an existing text. Remove specified characters from the text. Replace specified characters with other characters. Display the current text. Save the current text to a text history array. (BONUS) Display the text history array. (BONUS) 4.Utilize the StringBuilder class for efficient string manipulation. 5.Ensure robust error handling for invalid inputs or operations. 6.Implement additional text manipulation functionalities that: 1.Reverse the text. 2.Convert text to uppercase 3.Convert text to lowercase. Provide a user-friendly command-line interface or a Jpane interface with clear instructions and feedback.

Respuesta :

Explanation:

import java.util.ArrayList;

import java.util.Scanner;

class TextProcessor {

private StringBuilder text;

private ArrayList<String> textHistory;

public TextProcessor() {

text = new StringBuilder();

textHistory = new ArrayList<>();

}

public void appendText(String newText) {

text.append(newText);

}

public void removeCharacters(String charsToRemove) {

text = new StringBuilder(text.toString().replaceAll(charsToRemove, ""));

}

public void replaceCharacters(String oldChars, String newChars) {

text = new StringBuilder(text.toString().replace(oldChars, newChars));

}

public void reverseText() {

text.reverse();

}

public void convertToUppercase() {

text = new StringBuilder(text.toString().toUpperCase());

}

public void convertToLowercase() {

text = new StringBuilder(text.toString().toLowerCase());

}

public void displayText() {

System.out.println("Current Text: " + text);

}

public void saveToHistory() {

textHistory.add(text.toString());

}

public void displayHistory() {

System.out.println("Text History:");

for (String entry : textHistory) {

System.out.println(entry);

}

}

}

public class Main {

public static void main(String[] args) {

TextProcessor processor = new TextProcessor();

Scanner scanner = new Scanner(System.in);

boolean running = true;

while (running) {

System.out.println("\nChoose an option:");

System.out.println("1. Append text");

System.out.println("2. Remove characters");

System.out.println("3. Replace characters");

System.out.println("4. Reverse text");

System.out.println("5. Convert to uppercase");

System.out.println("6. Convert to lowercase");

System.out.println("7. Display current text");

System.out.println("8. Save text to history");

System.out.println("9. Display text history");

System.out.println("10. Exit");

int choice = scanner.nextInt();

scanner.nextLine(); // Consume newline

switch (choice) {

case 1:

System.out.println("Enter text to append:");

String appendText = scanner.nextLine();

processor.appendText(appendText);

break;

case 2:

System.out.println("Enter characters to remove:");

String charsToRemove = scanner.nextLine();

processor.removeCharacters(charsToRemove);

break;

case 3:

System.out.println("Enter characters to replace:");

String oldChars = scanner.nextLine();

System.out.println("Enter new characters:");

String newChars = scanner.nextLine();

processor.replaceCharacters(oldChars, newChars);

break;

case 4:

processor.reverseText();

break;

case 5:

processor.convertToUppercase();

break;

case 6:

processor.convertToLowercase();

break;

case 7:

processor.displayText();

break;

case 8:

processor.saveToHistory();

System.out.println("Text saved to history.");

break;

case 9:

processor.displayHistory();

break;

case 10:

running = false;

System.out.println("Exiting program.");

break;

default:

System.out.println("Invalid choice. Please enter a number between 1 and 10.");

break;

}

}

scanner.close();

}

}

ACCESS MORE