/** A little word-processor. * * @author * @version 1.0, due 2003-02-07 at 4pm */ public class EditableString { /** Stack of Characters to the left of the cursor; the ones * near the top of the stack are closest to the cursor. */ private Stack left; /** Stack of Characters to the right of the cursor; the ones * near the top of the stack are closest to the cursor. */ private Stack right; public EditableString() { left = new JavaStack(); right = new JavaStack(); } /** Another constructor. * @param left The text to the left of the cursor. * @param right The text to the right of the cursor. */ public EditableString(String left, String right) { // fill this in } /** Is cursor at the start of the text? */ public boolean isAtStart() { // fill this in return false; // replace this! } /** Is cursor at the end of the text? */ public boolean isAtEnd() { return false; // replace this! } /** Insert c into the string at the cursor. */ public void insertChar(char c) { // fill this in } /** Move cursor left 1 character. If we're already at the * start of the string, do nothing. */ public void moveLeft() { // fill this in } /** Move cursor left 1 character. If we're already at the * end of the string, do nothing. */ public void moveRight() { // fill this in } /** Delete character before the cursor. If there is none, * do nothing. */ public void backspace() { // fill this in } /** Delete character after the cursor. If there is none, * do nothing. */ public void delete() { // fill this in } /** Move cursor to start of the text. */ public void moveToStart() { // fill this in } /** Move cursor to end of the text. */ public void moveToEnd() { // fill this in } /** Convert to string. The cursor position is ignored. * @see toStringCursor */ public String toString() { // fill this in return ""; // replace this! } /** Like toString, but the special character | is included * to mark the cursor position. */ public String toStringCursor() { // fill this in return "|"; // replace this! } /** Search forward for the next occurrence of s that starts at the * cursor or later. If found, leave the cursor immediately after * that occurrence and return true. Else, leave the cursor at the * end of the text and return false. */ public boolean search(String s) { // fill this in return false; // replace this! } private static void printtest(EditableString es, String s) { System.out.println(s + ":\t" + es.toStringCursor().trim()); } /** A test method for this class. * @param args Command-line arguments, currently ignored. */ public static void main(String args[]) { System.out.println("Starting Word processor!"); System.out.println("----------"); EditableString es = new EditableString("initial contents",""); printtest(es, "Initial"); for (int i=70; i < 80; i++) { es.insertChar((char)i); printtest(es, "Typed"); } es.moveRight(); printtest(es, "moved right"); es.backspace(); printtest(es, "backspace"); es.moveLeft(); printtest(es, "moved left"); es.delete(); printtest(es, "deleted"); System.out.println("Is it at Start? " + es.isAtStart()); System.out.println("Is it at End? " + es.isAtEnd()); es.moveToStart(); printtest(es, "moved to start"); es.moveToEnd(); printtest(es, "moved to end"); } }