17-Feb-16 Methods. Overview In this presentation we will discuss these 4 topics: Main method vs. Jeroo methods Choosing behaviors to turn into methods.

Slides:



Advertisements
Similar presentations
Using Jeroo Dianne Meskauskas
Advertisements

13-Jun-14 OOP features of Jeroo. Overview In this presentation we will discuss these topics: OOP terminology Jeroo syntax constructors methods.
Container Classes A container class is a data type that is capable of holding a collection of items. In C++, container classes can be implemented as.
Nested If Statements While Loops
Chapter 1. The Phases of Software Development. Data Structure 2 Chapter outline  Objectives  Use Javadoc to write a method’s complete specification.
11-May-15 Control Structures part 2. Overview Control structures cause the program to repeat a section of code or choose between different sections of.
Programming in Jessica By Joaquin Vila Prepared by Shirley White Illinois State University Applied Computer Science Department.
SIMPLE PROGRAMS Jeroo – Chapter 4 –. Basic Concepts Jeroo (Java/C++/object-oriented) programing style is case-sensative. Be consistent in coding Logic.
Fall 2007CS 2251 Software Engineering Intro. Fall 2007CS 2252 Topics Software challenge Life-cycle models Design Issues Documentation Abstraction.
5-1 Facilitating Business over the Internet: The XML language CR (2004) Prentice Hall, Inc. The xml goals The main objects of xml: Diagrams: Blocks and.
9-Aug-15 Vocabulary. Programming Vocabulary Watch closely, you might even want to take some notes. There’s a short quiz at the end of this presentation!
30-Aug-15 Using Jeroo. Overview In this presentation we will discuss: What is Jeroo? Where did it come from? Why use it? How it works. Your first assignments.
Ch. 2 1 Karel – Primitive Instructions Basic tools with which all problems are solved (analogies: LeftSpinngingRobot, RightSpinningRobot, GuardRobot, etc)
17-Sep-15 Using Jeroo. Overview In this presentation we will discuss: What is Jeroo? Where did it come from? Why use it? How it works. Your first assignments.
Karel J Robot An introduction to BlueJ and Object- Oriented Programming.
1 Ch. 7 Recursion similar to iteration in that you repeatedly do a little bit of the task and then “loop” again and work on a smaller piece - eventually.
5-Oct-15 Introduction and Code. Overview In this presentation we will discuss: What is Jeroo? Where can you get it? The story and syntax of Jeroo How.
Karel J. Robot A Gentle Introduction to the Art of Object Oriented Programming.
16-Oct-15 Loops in Methods And compound conditions.
1 Functions Lecfture Abstraction abstraction is the process of ignoring minutiae and focusing on the big picture in modern life, we are constantly.
SE: CHAPTER 7 Writing The Program
25-Oct-15 Jeroo Code. Overview In this presentation we will discuss: How to write code in Jeroo How to run a Jeroo program.
CPSC 203. Use Case Diagram  A description of a system’s behavior as it responds to a request that originates from outside of that system. Specifies the.
1 karel_part2_Inheritance Extending Robots Tired of writing turnRight every time you start a new karel project. How do we avoid re-writing code all the.
13-Nov-15 Control Structures. Overview Without control structures, everything happens in sequence, the same way every time Jeroo has two basic control.
1 A simple C++ program // ======================================================= // File:helloworld.cpp // Author:Vana Doufexi // Date:1/4/2006 // Description:Displays.
15-100: Introduction to Programming w/ Java * Ananda Gunawardena -- Lecture – School of Computer Science – Phone : (x81559) – Office: Wean Hall.
16-Dec-15 Control Structures VB. Overview Without control structures, everything happens in sequence, the same way every time Jeroo has two basic control.
Container Classes  A container class is a data type that is capable of holding a collection of items.  In C++, container classes can be implemented as.
Modularity. Methods & Class as program unit A method is comprised of statement sequences and is often viewed as the smallest program unit to be considered.
INFO 414 Human Information Behavior Presentation tips.
Side effects A side effect is anything that happens in a method other than computing and/or returning a value. Example: public class hello { public int.
Programming in Karel Eric Roberts CS 106A January 6, 2016.
Karel J. Robot Chapter 6 Instructions That Repeat.
Mile-long hurdle race Suppose that we want to program Karel to run a one-mile long hurdle race, where vertical wall sections represent hurdles. The hurdles.
Karel the Robot – Review Primitive Commands move pickbeeper putbeeper turnleft turnoff Karel’s program statements are separated by a semicolon (;) Copyright.
1 Introduction 1. Why Data Structures? 2. What AreData Structure? 3. Phases of Software Development 4. Precondition and Postcondition 5. Examples.
ATS Programming Short Course I INTRODUCTORY CONCEPTS Tuesday, Feb 10th, 2009 Introduction to Programming.
11-Jun-16 Algorithms 2.2. Overview In this presentation we will discuss: What is an algorithm? 5 steps in developing an algorithm A Jeroo example.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 1 An Introduction to Visual Basic.NET and Program Design.
Introduction to Jeroo a small object oriented programming language.
Karel J. Robot Chapter 6 Instructions That Repeat.
Methods 9-Mar-17.
Implementation Topics Describe –Characteristics of good implementations –Best practices to achieve them Understand role of comments Learn debugging techniques.
CS 106A, Lecture 3 Problem-solving with Karel
Mile-long hurdle race Suppose that we want to program Karel to run a one-mile long hurdle race, where vertical wall sections represent hurdles. The hurdles.
Control Structures part 2
ANNOUNCEMENT The missed lecture will be made up this Monday evening in the Tech PC classroom (MG51). A tentative time interval is 6:30-8:00. The exact.
C++ Plus Data Structures
Copyright © 2008 by Helene G. Kershner
Jeroo Code 18-Jul-18.
2.2 Algorithms 21-Jul-18.
Copyright © 2008 by Helene G. Kershner
OOP features of Jeroo 8-Nov-18.
a small object oriented programming language.
Introduction and Code 18-Jan-19.
Overview Introduction to Jeroo: What is Jeroo? Where did it come from?
General Tips for Taking a Science Test
Control Structures 5-Apr-19.
General Tips for Taking a Science Test
Control Structures part 2
Control Structures 12-May-19.
General Tips for Taking a Science Test
General Tips for Taking a Science Test
2.2 Algorithms 26-Jun-19.
OOP features of Jeroo 3-Jul-19.
Control Structures VB part 2
IF 1-Jul-19.
Jeroo Code 7-Sep-19.
Presentation transcript:

17-Feb-16 Methods

Overview In this presentation we will discuss these 4 topics: Main method vs. Jeroo methods Choosing behaviors to turn into methods Writing a Jeroo method Preconditions and postconditions

Jeroo has many built-in methods Actions hop, turn, … Sensor methods isNet? isFlower? … The programmer can define additional methods to extend the behavior of every Jeroo.

Behaviors and methods Behavior = an action that an object can take or a task it can perform in response to a request from an external source Method = Collection of statements written in a programming language to describe a specific behavior. 1 st define and name a behavior 2 nd write code for the method

Which parts of the program should be methods? choose a behavior Any complex, well-defined step Any sequence of steps that more than 1 Jeroo will perform Any sequence of steps that occur several times. A good behavior to turn into a method has a very clear definition and is used more than once in the program.

Writing the method A Jeroo method contains the code describing what any Jeroo needs to do to carry out a particular behavior. method method_name ( ) { } //== method_name== Choose a name that is meaningful Empty parenthesis required on the header line (first line) Indent code inside the method Body of method Containing statements that describe how any arbitrary Jeroo can carry out this particular behavior.

Important differences Jeroo methods Can be many other methods Choose your own names Must be called by the main method Can’t instantiate in the method Main method Only one main method Must be called main Always comes first Instantiate Jeroos

Example of a Jeroo method //*********************************************************** //Turn Around: makes a Jeroo turn 180 degrees //*********************************************************** method turnAround( ) { turn(LEFT); } // === end turnAround === Good, descriptive name for the method The code is indented Comments clearly explain what the method does Notice that no Jeroo name is specified in the steps Everything in yellow is good!

Important difference Jeroo methods Define a behavior available to ALL Jeroos so do not specify which Jeroo performs the steps inside the method Example in a Jeroo method for any Jeroo pick(); hop(2); give(AHEAD); Main method All steps must specify which Jeroo does each action: objectname.method(); Example in main for a Jeroo named betty betty.pick(); betty.hop(2); betty.give(AHEAD);

Using a Jeroo method After you write your code Use it just like any other method method main( ) { Jeroo ali = new Jeroo(5,5,8); ali.plantCorner( ); } // === main === method plantCorner( ) { plant(); hop(); turn(RIGHT); hop(); plant(); } // === plant Corner ===

One method can call another The plantThree method is used twice in the plantRectangle method method plantThree( ) { plant( ); hop( ); plant( ); hop( ); plant( ); } //=== plantThree === method plantRectangle( ) { plantThree( ); moveDown( ); plantThree( ); }//=== plantRectangle === This code is missing most of its comments! Defined above Must also be defined somewhere A B

Preconditions and Postconditions A complete definition for a behavior includes: Preconditions Assumptions of what is true before the method is called Postconditions What will be true after the method is finished In Jeroo, the only things that change are: island cells (flower planted, net gone…) Jeroo attributes (location, number of flowers …)

Things to consider when writing a precondition What must be true for this method to work? Ask: does the Jeroo need A certain number of flowers? To be facing a particular direction? To be in a certain location? Ask: are the contents of certain island cells important? //******************************************** //Plant 3 flowers in a row starting at current location //PRECONDITIONS: // 1. There are 2 clear spaces directly in front // 2. Jeroo has at least 3 flowers //******************************************** method plantThree( ) {…

Things to consider when writing a postcondition Describe what is true after the method finishes Ask: how will the method change the number of flowers? the direction the Jeroo is facing? the Jeroo’s location? Ask: have the contents of certain island cells changed? // // POSTCONDITIONS: // 1. Three flowers have been planted, starting at the //beginning location and proceeding straight ahead // 2. The jeroo is standing on the last flower, // facing its original direction // ******************************************** method plantThree( ) {…

The End