CS 4773 Object Oriented Programming, Spring 2000
Assignment 2 Comments

Important test cases: Remote test files Grading: Other issues: 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