120 likes | 249 Views
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 of the crab’s present location. We can use this!.
E N D
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!
Look at the following function call:setLocation (getX(), getY()+1)In which direction will the crab move? • North • South • East • West
Movement Method Call
Turning Parameter What happens to the crab if you use a negative number?
Standard Java Class Import (Library) Statements Class Signature Method Signature
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.
How many other functions does the function act() call in its statements? • One • Two • Three • Four +
Method Call This conditional statement uses a built in function to turn an object if it hits the edge of the world. Method Body Method Call
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);