You are on page 1of 1

Section 3 Lesson 7: Using Sound and Keyboard Control

Try It: Practice Activities


Objectives

Write programming statements to include sound in a program

Write programming statements to include keyboard movements in a program

Try It/Solve It
1. Program an object to move left 5 steps and turn 2 degrees when the a keyboard key
is pressed, and move right 2 steps and turn 5 degrees when the b keyboard key is
pressed. Document your programming statements in your journal.
2. Review the course scenario JF_V01_S03_L07_S01_keyboard_keys. Save a copy of
a previously-created scenario. Replace the random movement with keyboard
movement, so the object can move in two directions, controlled by the cursor keys on
the keyboard. Document the code in your journal. Remember that because this is a
static method, it can be used in other classes if called using dot notation.
3. Program an object to make one sound when the x keyboard key is pressed, then
another when the y keyboard key is pressed. Record the sounds in Greenfoot and
save them to the scenario before programming the sound files into the class.
4. Program the prey instances in your game to make a sound when the predator eats
them. Document this code in your journal.

Copyright 2013, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their
respective owners.

You might also like