Setting the beak color on the Finch (setLED and sleep commands)

To set the Finch's beak color you must:

  1. Import the Color class at the very top of your program
  2. Create a Finch object in your program's main method
  3. Use the setLED method
    Choose a color ( Here are some colors: )
    • Color.RED
    • Color.GREEN
    • Color.BLUE
    • Color.YELLOW
    • Color.WHITE
  4. Give the Finch time to display the color before the program stops.
    To give the robot time to complete a task use the sleep method.
    The amount of time to wait is measured in milliseconds (1000 = 1 second)
  1. import java.awt.Color;
  2. Finch robo = new Finch();


  3. robo.setLED(Color.RED);





  4. robo.sleep(1000)

About colors

About sleep

Sleep is required to ensure that the program's output is visible to the user - e.g., if I set the LED to green and then to blue without giving the Finch time to display the colors, the LED will flash green for an infinitesimally short period.

The Finch needs to be given time to: move, talk, display lights and more.
When your program ends the Finch stops what it is doing, so always give it time to do the commands you tell it to do.

How well do you understand color and sleep?

Answer carefully. Remember that upper and lower case make a difference in Java.

  1. Fill in the code to complete the statement to turn the Finch named roy's beak blue (Using the Color class):
    roy.setLED( );
  2. Fill in the code to complete the statement to turn the Finch named roy's beak blue (Put one number in each box):
    roy.setLED( , , );
  3. What is the name of the method that tells the robot to change the color of its beak?
  4. How long does the robot, robo, wait after setting its beak to RED if it is given the command sleep(1000)?
    a) 1 second
    b) 10 seconds
    c) 100 seconds
  5. What is the method that tells the robot to wait for a certain amount of time?