Program: How many taps?

Description: Using variables, the Finch can count to remember what has happened and decide what to do next.

Create a program that will count how many times the Finch has been tapped in 5 seconds.
The robot should check to see if it has been tapped 10 times each second
At the end of the program the robot should say how many times it was tapped in words and also print it on the screen.

Pseudocode: (with some helpful code thrown in)

  1. Instantiate the Finch robot
  2. Declare a variable to count how many taps there have been (a whole number) int taps;
  3. Declare a variable to count how many times the Finch has checked to see if it has been tapped (a whole number)
  4. Set the number of taps so far to 0 taps = 0;
  5. Set the number of times checked so far to 0
  6. Loop: while the number of times checked is less than 50 ( checking 10 times a second for 5 seconds = 5*10 = 50)
    1. if the robot has been tapped
      • add 1 to the number of taps so far taps = taps + 1;
      • print a "*" to the screen so you get some feedback to know it is working
    2. wait one tenth of a second
    3. add one to the number of times checked
  7. The robot says "I was tapped " + taps + " times"
    Use the saySomething command to say it out loud and also write it to the screen:
    System.out.println("I was tapped " + taps + " times");

Challenge: Musical Taps

The first time the Finch is tapped it plays a middle C note

Each time the Finch is tapped it plays a note that is higher

After 5 taps the Finch says "Ouch, that's enough. stop"