CSc 101: Section 14 – Random, Math, and more Strings
In this section, you are going to be using random, doing some int/string/float math, and continuing to work with strings.
This section is a “take-home” section.
To receive full credit for “attending” this section, complete all problems and then submit them to D2L by 5:00pm on Wednesday, November 22nd.
Problem 1
|
Write a scetch named secton_14_1 .
In this sketch, you will display whatever text the user types on the keyboard, as shown in the picture.
Whenever the mouse is clicked on the canvas, the text is cleared frm the screen, and the user can type something new.
The text should be size 50, and the canvas should be large enough to fit a reasonable amount of text, like shown.
|
Problem 2
|
Write a sketch named section_14_2 .
This time, your canvas should be wider and narrower.
Your canvas should have the "digits" label as shown.
You program will display only the digits 0-9 that the user types.
If the user types other letters or symbols, they should not be displayed!
Also, pressing the space-bar will clear all the digits off of the canvas, and the user can types something new.
|
Problem 3
|
Write a sketch named section_14_3 .
This program will generate two random numbers between 0 and 20 on each frame (each time draw() runs).
One of the numbers will be converted to an integerer (thus, getting rid of the decimal places) and the other will be left as a float.
These two numbers will be displayed on the canvas, as shown in the screen capture.
Below, the sum of the two numbers will be displayed, also in integer form.
You should set the frameRate() to a small number (for example, 1) so that the numbers dont change too quickly.
|
Problem 4
|
Write a sketch named section_14_4 .
This sketch will read in numbers that you type.
As you type in digits, the digits will be displayed on the top line with the "limit" label.
Once you hit "Enter" (represented by the "\n" special character) then the number will be cleared.
In addition to clearing the number, a number will appear next to the "random number" label.
This number should be a randomly-generated number between 0 and the number that the user typed in before hitting the ENTER key.
|
Solutions will be posted after the section is turned in