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.

Slides:



Advertisements
Similar presentations
C Functions. What are they? In general, functions are blocks of code that perform a number of pre-defined commands to accomplish something productive.
Advertisements

Copyright 2008 by Pearson Education Building Java Programs Chapter 8 Lecture 8-3: Encapsulation, toString reading: self-checks: #13-18,
Chapter 8 Scope, Lifetime and More on Functions. Definitions Scope –The region of program code where it is legal to reference (use) an identifier Three.
Cosc 5/4730 Input Keyboard, touch, and Accelerometer.
Games and Simulations O-O Programming in Java The Walker School
Program: Little Crab Mr Gano.
CHAPTER 13 Object Oriented Programming. Objectives  Design class definitions  Implement data hiding and encapsulation  Use accessor and mutator methods.
Week 9: Methods 1.  We have written lots of code so far  It has all been inside of the main() method  What about a big program?  The main() method.
ITERATIVE CONSTRUCTS: DOLIST Dolist is an iterative construct (a loop statement) consisting of a variable declaration and a body The body states what happens.
Example 2.
Comp 205: Comparative Programming Languages User-Defined Types Enumerated types Parameterised types Recursive types Lecture notes, exercises, etc., can.
Introduction to Programming with Java, for Beginners Scope.
 2003 Prentice Hall, Inc. All rights reserved Introduction Modules –Small pieces of a problem e.g., divide and conquer –Facilitate design, implementation,
Simple Python Loops Sec 9-7 Web Design.
SuperCorners. Problem The Corners sample robot has a simple strategy: first, move into a corner of the arena, and second sweep the gun back and forth.
Visual C++ Programming: Concepts and Projects Chapter 6A: Methods (Concepts)
EDT Chapter 41 Coordinate Systems Cartesian, Relative and Polar Sacramento City College EDT 310.
Artificial Intelligence Lecture 8. Outline Computer Vision Robots Grid-Space Perception and Action Immediate Perception Action Robot’s Perception Task.
Comments are for people Header comments supply basic information about the artifact.
1 Java Methods & Classes – Lecture 4 Prepared by: Ahmad Ramin Rahimee Assistant Professor ICTI.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Recursion COMP 102 # T1.
Do Now Write down 4 things that you know about a COORDINATE GRID.
Copyright 2010 by Pearson Education Building Java Programs Chapter 8 Lecture 8-2: Object Behavior (Methods) and Constructors, Encapsulation, this reading:
CPS120: Introduction to Computer Science Decision Making in Programs.
Introduction to Method. Example Java Method ( 1 ) The 2 types (kinds) of methods in Java Class methods Instance methods Methods can do more work than.
CPS120: Introduction to Computer Science Functions.
CPS120: Introduction to Computer Science Lecture 14 Functions.
Introducing Python CS 4320, SPRING Resources We will be following the Python tutorialPython tutorial These notes will cover the following sections.
COMPUTER PROGRAMMING. Functions’ review What is a function? A function is a group of statements that is executed when it is called from some point of.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
1 Structure of a C Program (continued) Presentation original from Dr. Turner’s class USF - COP C for Engineers Summer 2008.
Lesson 2: Reading a program. Remember: from yesterday We learned about… Precise language is needed to program Actors and Classes Methods – step by step.
1 Building Your Own Turtle Functions For making really cool pictures!
Week 8 - Friday.  What did we talk about last time?  Static methods.
Methods CSCI 1301 What is a method? A method is a collection of statements that performs a specific task. Pre-Defined methods: available in Java library.
Introduction to Functions CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Review Expressions and operators Iteration – while-loop – for-loop.
 Static  Example for Static Field  Example for Static Method  Math class methods  Casting  Scope of Declaration  Method Overloading  Constructor.
Chapter 2 – The Little Crab Program:. Little Crab Scenario Inheritance: The Arrows Denote Hierarchy Crab is an Animal Animal is an Actor Therefore, It.
Methods.
Creating Scenarios In Greenfoot. Greenfoot Scenarios are made up of: Greenfoot Scenarios are made up of: A World class. A World class. Actor classes.
COP 2220 Computer Science I Topics –Breaking Problems Down –Functions –User-defined Functions –Calling Functions –Variable Scope Lecture 4.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 6A Methods (Concepts)
PYTHON FUNCTIONS. What you should already know Example: f(x) = 2 * x f(3) = 6 f(3)  using f() 3 is the x input parameter 6 is the output of f(3)
Motion and Force Chapter Three: Motion 3.1 Position and Velocity 3.2 Graphs of Motion 3.3 Acceleration.
1 CS 106 Computing Fundamentals II Chapter 42 “Sub Procedures And Functions” Herbert G. Mayer, PSU CS Status 8/5/2013 Initial content copied verbatim from.
1 Sections 6.4 – 6.5 Methods and Variables Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Copyright 2010 by Pearson Education Building Java Programs Chapter 8 Lecture 8-3: Constructors; Encapsulation reading: self-checks: #13-18,
Python Programming Module 3 Functions Python Programming, 2/e1.
Lecture 12: Dividing Up Work. Why Using Functions Divide-and-conquer making large program development more manageable. Software reusability Use existing.
Copyright 2010 by Pearson Education Building Java Programs Chapter 8 Lecture 8-2: Object Behavior (Methods) and Constructors, Encapsulation, this reading:
Python Programming Module 3 Functions Python Programming, 2/e.
Topics Introduction to Repetition Structures
Function There are two types of Function User Defined Function
Functions.
Control Structures (Structured Programming) for controlling the procedural aspects of programming CS1110 – Kaminski.
Functions, Procedures, and Abstraction
Building Java Programs
Building Java Programs
Arrays.
Topics Introduction to Value-returning Functions: Generating Random Numbers Writing Your Own Value-Returning Functions The math Module Storing Functions.
COMPUTER PROGRAMMING SKILLS
Control Structures (Structured Programming) for controlling the procedural aspects of programming CS1110 – Kaminski.
East West Move to Table 2 N/S
Building Java Programs
START DIRECTIONS QUIZ.
Indentation & Comments
Corresponds with Chapter 5
Parameters and Arguments
Coordinate Systems Cartesian, Relative and Polar
Presentation transcript:

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!

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

Movement Method Call

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

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

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.

Look at the following class:

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

Look at the following class:

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.

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);