CS 106 Winter 2016

Lab 01: Input and output


Question 1 Reading text

Download the file shakespeare.txt (Shakespeare's Sonnet #130) and add it to the data folder of an empty sketch. Now write a sketch as follows:

If all goes well, you should see output like this in the Console window:

My mistress’ eyes are nothing like the sun;
Number of lines:
14
Longest line:
48
Number of words:
123

Of course, you shouldn't just print these numbers out explicitly! You have to compute the stats from the input file. Note that to compute the longest line and the number of words, you'll probably need at least one loop.

Save this sketch as TextStats. Put it in a folder that will hold all your Lab 01 sketches.

Question 2 Writing text

For example, the screenshot on the left might produce the clicks.txt file on the right.

126 206
168 125
211 393
429 387
425 185
307 118
63 391
291 293

The resulting sketch will be similar to the example shown in the online Processing documentation for the createWriter() function. But that example draws a dot every frame; you must draw a circle only in response to mouse clicks.

Save this sketch as RecordClicks. Put it in a folder that will hold all your Lab 01 sketches.

Question 3 Out to pasture


Save this sketch as OutToPasture. Put it in a folder that will hold all your Lab 01 sketches.

Submission

Remember to review the Code Style Guide and use Processing's built-in auto format tool. Then review the How To Submit document. At the top of all of your source files, be sure to include a comment with your name and student ID number. When you're ready, zip all the sketches created above (TextStats, RecordClicks, and OutToPasture) into a single archive called L01.zip and upload that file to LEARN.