CS 117 Homework Assigned Monday February 19. Due Monday February 26.

No Comment

Recall that there are two ways to put comments in a Java program.
 (1) The // format
     For example:

      // This is a comment
 
     or, for example: 

      int x;   // this is also a comment

 (2) The /* ... */ format
     For example:

     int x ;  /* What's inside here is a comment */

     or, for example: 

     /* This part of the program doesn't
        work very well

        i = i/0;

     */

Write a program that will read in a text file containing a Java class definition and write out another text file which is the input file with all comments removed. For example, if the input file contains the text:
// This class definition is weird.
// Written by Jack Goldfeather
// Last Modified February 21, 2007 

class MyClass {

// Here are the variables

   int i,j;

// Here is a method

   public void myMethod(int n)

     {
         i = n;   /* i is an integer */
    
       // Here is where something is printed

         System.out.println(i);  /* print something */

      /* This code is commented out because it doesn't work

         j = i/0;

      */
    }
}

The output file should contain:

class MyClass {


   int i,j;


   public void myMethod(int n)

     {
         i = n;  
    

         System.out.println(i);  


    }
}
Note that if the input file compiled and ran as part of a Java program, then so should the output file. Test your comment-stripping program by trying to compile and run the output file. Assume that the strings "//" "/*" and "*/" can only appear for comments, e.g. String x = "//fooled you" is not allowed.