Step 8

Testing the “WordSpammer” class


Next, let’s go back to “Main” to test out the class we made.

In here, add the code as shown to test out both the functions we made! Just like before, we need to create a new datatype. (When we create a new variable from a custom datatype, we call that variable an instance of that custom datatype. Here “ws” is an instance of a WordSpammer, we’ll see this more later.)

Note: In the example, you will see gray text “spamString:” and “timesToSpam:”. Do not type these! They will appear automatically!

Feel free to use your own strings/words to test this out. Once you run the code, you should see something similar to what is shown here. Now we can clearly see the difference between the “println” and “printf” functions! If the code doesn’t work, go back and check your code for any errors.