/* File: TextEditor.java Developed for Problem Solving with Java, Koffman & Wolz Appears in Figure 5.19 */ import myIO.*; public class TextEditor { public static void main(String[] args) { // Create an EditableString object. EditableString editString = new EditableString(); int quit = 5; String choices[] = {"enter new string", "search", "insert", "delete", "replace", "quit"}; // Read a string and perform each edit operation selected by user. String toEdit = IO.getString("Enter a string to edit"); editString.setText(toEdit); for (int editOp = IO.getChoice("Edit '" + editString.toString() + "' -- select an edit operation:", choices); editOp < quit; editOp = IO.getChoice("Edit '" + editString.toString() + "' -- select an edit operation:", choices)) { if (editOp == 0) { //. . . } else if (editOp == 1) { String target = IO.getString("Enter string to find:"); int pos = editString.search(target); if (pos >= 0) IO.displayResult("target string found at " + pos); else IO.displayResult("target string not found"); } else if (editOp == 2) { String newString = IO.getString("Enter string to insert:"); int index = IO.getInt("Enter index of insertion point:", 0, editString.toString().length()); IO.appendOutput("new text is '" + editString.insert(newString, index) + "'"); } else if (editOp == 3) { //. . . } else if (editOp == 4) { //. . . } } // end for IO.appendOutput("The final string is '" + editString.toString() + "'"); IO.displayOutput(); System.exit(0); } } // class TextEditor