COSC 135 B Programming
Assignment 6
Tom Linton,
Fall 2000, Central College
In a file named SimpleEdit.java, write a program that
performs several simple word processing commands. The user begins by entering
a String to edit, and then selects operations from a checkbox group, and
presses buttons to carry out the operations. The commands that the user
is allowed to perform are:
-
Search: read in the String to search for and, if it is present in
the String to edit, display the location (index) of the searched for String.
If the String is not present, you should print a line saying that the String
is not present.
-
Insert: The users enters a String to insert and the location to
insert at (an integer). For example, if the editing String is "hello there
Tom" and the user says to insert "Tami and " at location 12 (the location
of the 'T' in Tom), the result would be "hello there Tami and Tom".
-
Replace: The user enters String1 and String2. Your code should locate
the first occurence of String1 in the editing String and replace it with
String2. For example, if the editing String is "Hello there Tom", and the
user gives String1 = " there" and String2 = ", how are you", the result
would be "Hello, how are you Tom". If String1 does not occur in the editing
String, you should display a line saying so.
-
ShowLocations: This method should display the numbers corresponding
to the java indicies that go with each letter in the editing String. I'd
suggest displaying a repeated pattern of 0123456789 right above the editing
String. For example, from the output:
01234567890123456789012345678901234
Hello there Tom, how are you doing.
You can tell that the word "Tom" starts at location 12, while "are" starts
at 21.
-
CountWords: This command will display the number of words in the
editing String. You can assume that spaces, returns, tabs or common punctuation
marks (comma, exclamation point, question mark and period) separate the
words in the user's String. You should use a StringTokenizer for
this command.
-
AverageLength: This command should calculate the average number
of letters in the words in the editing String. This can be calculated as
the total number of letters (don't count punctuation or white space) divided
by the number of words.
You should display results and-or messages in a TextArea, and
continually update a field that holds the current version of the String
being edited. Each command should be available through a checkbox, within
a checkbox group. Make your GUI easy to understand. For example, the replace
command requires two inputs from the user. The fields for these inputs
should "line up" with the checkbox for this command. See how the "enter
number" field in our Roulette GUI aligns itself
with the "bet on a number" checkbox.