Step 4

Testing the WordChecker class


Now that we’ve completed all the code for our “WordChecker” class, let’s test it out! Open up the “Main” file.

Inside the “Main” file, add the code as shown to test out the “WordChecker” class.

On line 10, we create a new variable of type “WordChecker”. Whenever we are making a new class, we are actually making a whole new custom datatype! In order to create these datatypes we use the word new as well as the name of the datatype and (). Here we are making a new WordChecker datatype and give it the name “wc”.

Then on lines 11-14, we are testing out each of the possibilities in our WordChecker class. Whenever we are testing, we want to make sure that all of our code works. This is why here we are testing strings of all the different lengths that we wrote code for. Feel free to write your own text in the strings, these are just examples. (Line 13 is cut off, but only because it has a lot of text, the content isn’t important, just the fact that it has a lot of text)

After writing all this test code, run the program! If everything is working correctly you should see something like what is shown here. If not, go back and check your code for any mistakes/errors.