Specifications

If you did not keep the scenario, then download piano-complete.gfar, save it to a convenient location like the Desktop and launch the scenario.

Open the editor for the Key class and find the act() method.

Make sure you have completed the Try It for Adding Mouse Clicks. Your act() method should look like the following though line numbers may vary.

Compile and run your scenario to verify it works correctly, playing sounds with key presses and mouse clicks.

If you have problems, ask a guild member or the instructor for help as needed.

Prepare a text file named trace.txt to record the flow of the Key class act() method.

Using the Greenfoot debugger, trace the flow of the code in the Key class act() method by listing the line numbers that are executed when the "A" keyboard key is pressed. Record the line numbers in trace.txt.

In this exercise, we work with loops and arrays in the Piano scenario.

Specifications

Start Greenfoot and open the Piano scenario from the last Try It.

If you did not keep the scenario, then download piano-complete.gfar, save it to a convenient location like the Desktop, unzip the file, and launch the scenario.

Prepare a text file named loop.txt to record the data from the following steps.

Locate the makeKeys() method and notice the two loops, one for the white keys and one for the black keys.

Add a System.out.println() statement to both loops that prints the values of the arguments sent to the Key constructor with a vertical bar (|) separating each value.
For example, add the following statement inside the white-key loop: