Presentation is loading. Please wait.

Presentation is loading. Please wait.

Movement. Fixed Movement setLocation (x, y) Makes the crab move to a fixed cell x,y Relative Movement The functions: getX() getY() Fetch the x and y coordinate.

Similar presentations


Presentation on theme: "Movement. Fixed Movement setLocation (x, y) Makes the crab move to a fixed cell x,y Relative Movement The functions: getX() getY() Fetch the x and y coordinate."— Presentation transcript:

1 Movement

2 Fixed Movement setLocation (x, y) Makes the crab move to a fixed cell x,y Relative Movement The functions: getX() getY() Fetch the x and y coordinate of the crab’s present location. We can use this!

3 Look at the following function call: setLocation (getX(), getY()+1) In which direction will the crab move? 1.North 2.South 3.East 4.West

4 Movement Method Call

5 Turning Parameter What happens to the crab if you use a negative number?

6 Standard Java Class Method Signature Class Signature Import (Library) Statements

7 Functions and Methods A function is a named sequence of statements that performs a desired operation. This operation is specified in a function definition. NAME( LIST OF PARAMETERS ): STATEMENTS There can be any number of statements inside the function, but they have to be indented from the left margin. Creating a new function gives you an opportunity to name a group of statements. Functions can simplify a program by hiding a complex computation behind a single command and by using English words in place of arcane code. Creating a new function can make a program smaller by eliminating repetitive code.

8 Look at the following class:

9 How many other functions does the function act() call in its statements? 1.One 2.Two 3.Three 4.Four +

10 Look at the following class:

11 Method Call Method Call Method Body This conditional statement uses a built in function to turn an object if it hits the edge of the world.

12 Function (or Method) Call The value or variable, which is called the argument of the function, has to be enclosed in parentheses. It is common to say that a function “takes” an argument and “returns” a result. The result is called the return value. turn (angle);


Download ppt "Movement. Fixed Movement setLocation (x, y) Makes the crab move to a fixed cell x,y Relative Movement The functions: getX() getY() Fetch the x and y coordinate."

Similar presentations


Ads by Google