New Required Java Skills: Using a random number generator
Resources available for teachers. Get Access
You can use a method in the Finch class to change the color of the Finch’s beak! The Finch’s beak actually has three tiny light elements inside it. One is red, one is green, and one is blue. This is important for programming the beak. To change the color of the beak, use the setLED() method.
The setLED() method requires four parameters. The red parameter controls the amount of red light from 0 (none) to 255 (maximum brightness). The green and blue parameters control the amount of green and blue light, respectively, from 0 to 255. By combining different amounts of these three colors, you can also create other colors. For example, red light and blue light will combine to make purple. The fourth parameter sets the time in milliseconds that the beak should stay this color. The beak will turn off when this time is up.
Try the command shown above. The Finch’s beak should turn red for two seconds.
Write a program to make the beak turn purple, then aqua, then yellow.
Write a program that asks the user for the amount of red, green, and blue in the beak color. The beak should stay that color for three seconds.
You can also use the setLED() method with only the first three parameters (red, green, and blue). When used with three parameters, this method will set the beak color and then move on immediately to the next line in the program.
Write a program to make the Finch move forward, then back. When the Finch is moving forward, its beak should be green. When the Finch is moving back, its beak should be red.
Make the Finch into a spinner for a game like Twister or Chutes and Ladders. Create a program that spins the Finch for a random amount of time; you will need to use a random number generator to implement this program. The Finch’s beak should be red while it is spinning and green when it stops.