WARNING: This pages is using the global variables.php file. All 240 course websites after Fall 2018 should use a relative path to a variables.php file in the semester's root directory instead!

CS 240 - Fall 2018

TA Tips for the Spelling Corrector Lab - Fall 2018

Here are some things to consider that will help you out:

  1. Visibility Modifiers in Java and C++
    In C++, constructors are declared to be public by default if preceeded by the public keyword.
    In C++, you could have some code that looks like this:
    #include <cstdio>
    
    class Words {
          FILE* file;
       public:
          Words();
          Words(FILE*);
          //...
    }
    
    and by default, these would be public.
    Java does things a little differently. The "public" keyword, doesn't blanket all declarations like it does in C++. In Java, you must declare EVERY class, constructor, variable, method, etc... to be public, protected, or private. If you don't the default is what is called "package protected". That means only classes in the same package will be able to see or use that class, constructor, variable, method, etc....
    So, instead of doing this:
    import java.io.File;
    
    class Words {
       File file;
    
       Words() { ... }
       Words(File file) { ... }
    }
    	

    Do this:
    import java.io.File;
    
    public class Words {
       private File file;
    
       public Words() { ... }
       public Words(File file) { ... }
    }
    

    That way, we can call this constructor, even if we are not in the same package as you.


  2. Java Packages vs. C++ Namespaces
    This project is in the spell package. Packages are similar to namespaces in C++.
    #include <cstdio>
    
    namespace spell {
       class Words {
          private:
             FILE* file;
          public:
             Words();
             Words(FILE*);
       }
    }
    
    This is like the following in Java:
    package spell;
    
    import java.io.File;
    
    public class Words {
       private File file;
    
       public Words() { ... }
       public Words(File file) { ... }
    }
    

    You need to make sure that your code is in the same package as the interface we give you (i.e. The spell package). If it is not in the same package, we won't be able to call it because we don't know where it is. This is one reason why including the specific "public" declaration is so important. If you don't put that on your constructor, or class, or whatever, it is package protected, and only the classes inside of package.spell can use it. Our test driver is NOT in the spell package and won't be able to access it.