Methods 9-Mar-17.

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.
Introduction to Visual Basic.NET Uploaded By: M.Sheraz anjum.
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.
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.
Introduction to problem solving. Introductory Discussion? What problems are you faced with daily? Do you think a computer can be designed to solve those.
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.
06/10/ Working with Data. 206/10/2015 Learning Objectives Explain the circumstances when the following might be useful: Disabling buttons and.
Karel J. Robot A Gentle Introduction to the Art of Object Oriented Programming.
16-Oct-15 Loops in Methods And compound conditions.
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.
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.
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.
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.
Objective You will be able to define the basic concepts of object-oriented programming with emphasis on objects and classes by taking notes, seeing examples,
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.
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.
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.
Macros in Excel Using VBA Time Required – 5 hours.
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.
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
Systems Analysis and Design in a Changing World, Fourth Edition
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.
Functions.
OOP features of Jeroo 8-Nov-18.
a small object oriented programming language.
Slides by Steve Armstrong LeTourneau University Longview, TX
A Gentle Introduction to the Art of Object Oriented Programming
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.
Nested If Statements While Loops
Use Case Modeling Part of the unified modeling language (U M L)
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:

Methods 9-Mar-17

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. 1st define and name a behavior 2nd 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. Choose a name that is meaningful Empty parenthesis required on the header line (first line) Indent code inside the method Sub method_name ( ) End Sub ‘== method_name== Body of method Containing statements that describe how any arbitrary Jeroo can carry out this particular behavior.

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

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

Important difference 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) 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)

Using a Jeroo method After you write your code Use it just like any other method Sub plantCorner( ) plant() hop() turn(right) End Sub ‘ === plant Rectangle === Sub main( ) Dim Ali as Jeroo = New Jeroo(5,5,8) Ali.plantCorner( ) End Sub ‘ === main ===

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

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 Sub 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 ‘ ******************************************** Sub plantThree( ) …

The End