Assignment 2 has 3 parts.
In this assignment you will write several methods which will remove all of the multiple blank characters from a string. The prototype for these methods will be something like:
public static String RemoveBlanks(String s)Each will return a new string created from the String s in which multiple consecutive blanks will be replaced by single blanks. Leading and trailing blanks will also be removed. For example, if the string passed to this function is "    This     is a     test    ", then the returned string will be "This is a test".
Hand in hard copies of all source code and output where appropriate. Use this as the cover sheet. Be sure that it is completely filled in.
Note that your methods are to handle only multiple blanks and not modify tabs, carriage returns, newlines, etc.
In this part of the assignment you will be writing two classes, BlankRemovers and BlankTester. The first class will have 4 public static methods and the second will be an application which tests the methods of the first class.
You will be writing 3 methods called RemoveBlanksString, RemoveBlanksBuffer, and RemoveBlanksTokenizer. These methods will differ only in their implementation.
RemoveBlanksString will use charAt to examine each character of the string in sequence and append a single-character string each time the character examined is to be kept.
RemoveBlanksBuffer will also use charAt, but it will use a StringBuffer to accumulate the characters and then convert the result to a String when complete.
RemoveBlanksTokenizer will also use a StringBuffer, but instead of examining characters one at a time, it will use a StringTokenizer to pull tokens out of the input string.
Also write a function:
public static int BlankCounter(String s)which returns the number of blanks in the String s.
Put all four methods in a class called BlankRemovers.
Write a main program, BlankTester that takes a single command line argument and feeds it to the methods in the BlankRemovers class. It should output (to standard output) the results of each of the blank-removing methods used on this input and check to see that the three results are the same. An appropriate warning message should be displayed of they are not. It should also output the number of blanks in the input string as well as each of the three output strings. The output should be done in a way which allows you to tell if the leading and trailing blanks have been removed.
Add an additional public static method to the BlankRemovers class which tests the other four methods of the class. This new method should have the prototype
public static boolean Verify(boolean verbose)and should return true if the tests are successful and the false otherwise. If verbose is false, it should produce no output. If verbose is true, detailed information about which tests were run and the results of the tests should be sent to standard output.
Verify should call each of the other methods in the class with several test strings and compare the results with the known correct answers. Make up test data which tests all of the cases that could occur. Part of your grade will be based on the quality of your test data.
Write an application called SimpleBlankTester which takes an optional command line argument of "verbose" and calls Verify with either a true or false parameter. In either case it should report the return value of the Verify method of the class BlankRemovers.
Run this main program with and without the optional parameter and hand in the output generated.
Write an applet which will have seven buttons, Read Short, Read Medium, Read Long, Local/Remote, ApplyString, ApplyBuffer and ApplyTokenizer.
The first three buttons will read in one of the files input.short, input.medium, or input.long and obtain a single string from the file. Use the class FileIO.class which is available in /usr/local/courses/java/cs4773/spring2000/assign2. This class contains a public method:
public static String ReadEntireFile(String name, Applet ap)which reads the file with the given name and returns the contents of that file as a String. It returns null if an error occurs.
When one of these buttons is pushed, the applet should display an appropriate warning message if there was an error. Otherwise it should display the name of the file, its size, and the number of blanks in the file. It should also display the first 10 characters of the String, or the entire String if it is shorter than 10 characters.
The next button toggles between local and remote mode.
The applet starts in local mode and in this case the first three buttons
act as described above. When in remote mode, each of the files
has the string
"/classes/cs4773s2000/assign/assign1test/"
prepended to it. This causes the file to be read from this web address
rather than from the place where the applet was loaded.
The last three buttons will each run one of the RemoveBlanks methods on this string, keeping track of the time it takes to perform the removal and displaying this time in milliseconds. It should also display the size of the output string, the number of blanks in this string, and up to the first 10 characters in the String.
Use the method System.currentTimeMillis() which returns the current
time in milliseconds as a long.
This value is the number of milliseconds since midnight, January 1, 1970.
A very small amount of extra credit will go to the student
in the class who first
correctly posts on the course newsgroup the first date on which this number
will become negative.
You must also post the method you used to determine your answer and compare
the problem caused by this to the Y2K bug.
It is up to you to figure out how to format the output of the applet in a useful way. All output produced by the applet should appear in the applet window. A good design for your output is important. Your full name should appear somewhere in your applet window.
Put the applet on your web site with a link to it from your course home page. Make sure that others can run your applet from their browser. Make up test files of sizes of about 10, 1000, and 10,000 bytes to be used for the input files. These will have to be stored in the same directory as your applet. You should not assume that the remote file will not change after you turn in your assignment.