CS 4773 Object Oriented Programming, Spring 2000
Assignment 2 Comments
Important test cases:
- empty string
- string of only blanks
- string with no blanks
- string with no multiple blanks
- string with leading and trailing blanks
- string with multiple blanks
Remote test files
- input.short: 4 blanks only, results in a string a size 0.
- input.medium: 1024 bytes, result: size = 935, blanks = 164
- input.long: 10240 bytes, result: size = 9349, blanks = 1669
Grading:
- Total of 30 points
- One point taken off for each missing important test
- One point taken off it I could not tell what mode the local/remote was in
- Two points taken off if input.short was not handled correctly
Other issues:
- Most people assumed a font height
- Also assumed that a button of a certain height would fit
- The status line not a good place to indicate mode of toggle as
the browser will write to the status line when doing network I/O
- When using BorderLayout, use the constants, not the strings
- It is usually not a good idea to use FlowLayout
- Button locations should be logical
- Should be able to tell when the calcualtion has been started
- It is best to keep inforamation about the input on the screen
after the blanks have been removed
- It would be nice to have some instructions on the screen.
- You do not have to use new String("xx");
- Avoid using if () ; else { }
- Clear out info on screen when not relevant
- Use arrays for test strings
- Note that StringTokenizer allows you to specify the delimiters to use You should read the documentation on StringTokenizer: specify delimiters
Avoid doing something and then undoing it.
Don't put in a blank and then take it out, unless necessary.
Sample code:
public static String removeBlanksString(String s) {
String s1 = "";
int i = 0;
while ( (i < s.length()) && (s.charAt(i) == ' ') ) i++;
while (i < s.length()) {
while ( (i < s.length()) && (s.charAt(i) != ' ') ) {
s1 = s1 + s.charAt(i);
i++;
}
while ( (i < s.length()) && (s.charAt(i) == ' ') ) i++;
if (i >= s.length()) return s1;
s1 = s1 + " ";
}
return s1;
}
public static String removeBlanksBuffer(String s) {
StringBuffer s1;
int i = 0;
s1 = new StringBuffer();
while ( (i < s.length()) && (s.charAt(i) == ' ') ) i++;
while (i < s.length()) {
while ( (i < s.length()) && (s.charAt(i) != ' ') ) {
s1.append(""+s.charAt(i));
i++;
}
while ( (i < s.length()) && (s.charAt(i) == ' ') ) i++;
if (i >= s.length()) break;
s1.append(" ");
}
return s1.toString();
}
public static String removeBlanksTokenizer(String s) {
StringBuffer s1;
StringTokenizer tok;
s1 = new StringBuffer();
tok = new StringTokenizer(s," ");
if (tok.hasMoreTokens())
s1.append(tok.nextToken());
while (tok.hasMoreTokens()) {
s1.append(" " +tok.nextToken());
}
return s1.toString();
}
Grade distribution so far (out of 30)
30 0
29 1
28 1
27 3
26 2
25 3
24 2
23 2
22 1
21 1
20 1
below 20: 6
pending grades: 5
Links