Using Operators to Move Objects

Using Operators to Move Objects
Open the FlyingBird_Lesson2 program. Use save as and resave the program as
FlyingBird_Lesson3. In the FlyingBird_Lesson3 program do the following:
Add the methods and variables as indicated below.
Part 1: Open the editor for the Bird1 class and create the following variables and

Name of Method Purpose Variables
public void applyGravity() This method will simulate gravity causing the
bird to fall. Use the bird’s current x and
increment the Y using the velocity variable.
Part 1: ACTIVITIES TO DO – Complete the following 1-4 activities
1) Open the source code editor for the Bird1 and create the global instance variable for
velocity and the class variable for gravity in the field area.
 velocity is a double, private variable, set it to 0
 Gravity is a static final double private variable, set it to 0.5
2) Under the act method, Create the method header for the applyGravity() method. It
will be public and void.
This method has two statements.

Don't use plagiarized sources. Get Your Custom Essay on
Using Operators to Move Objects
Just from $13/Page
Order Essay

a) Use the setLocation(int x, int y) method and write a statement that will get the
current x and y for the bird and add the velocity variable to the Y coordinate.
b) Write an expression that will update the velocity variable by adding the gravity
variable to it.
3) Add the applyGravity() method to the act() method to call it.
4) Test to see if the bird falls. Debug if needed.
Turning It In
Using Operators to Move Objects
Create a zip file called Using_Operators_To_Move_Objects and place the entire
FlyingBird_Lesson3 Greenfoot folder in it. Turn in the zip file to the Using Operators to
Move Objects assignment.