Adding Behaviors (methods)

Slides:



Advertisements
Similar presentations
Chapter 4: Control Structures I (Selection)
Advertisements

Javascript It’s not JAVA. What do these all have in common?
Games and Simulations O-O Programming in Java The Walker School
Program: Little Crab Mr Gano.
Where do objects come from? Objects are instances of classes We instantiate classes: –e.g.new chapter1.Terrarium() –There are three parts to this expression:
Test review. When? Monday 9/27 in class Know Greenfoot How many classes? Top-most classes? What does each button do? Lowest child class?
CS190/295 Programming in Python for Life Sciences: Lecture 1 Instructor: Xiaohui Xie University of California, Irvine.
Object Oriented Software Development
Imperative Programming
Greenfoot. Getting Started Open the Greenfoot download site: Select Greenfoot
Invitation to Computer Science, Java Version, Second Edition.
1 Chapter 3 and 6– Classes, Objects and Methods Object-Oriented Programming Concepts – Read it from Java TutorialJava Tutorial Definition: A class is a.
Object-Oriented Programming (OOP). Implementing an OOD in Java Each class is stored in a separate file. All files must be stored in the same package.
Principles of programming languages 5: An operational semantics of a small subset of C Department of Information Science and Engineering Isao Sasano.
© Jalal Kawash Programming Peeking into Computer Science 1.
JavaScript Syntax and Semantics. Slide 2 Lecture Overview Core JavaScript Syntax (I will not review every nuance of the language)
Use Case Driven Analysis Requirements Use Case Use Case Description System Sequence Diagram Chapter 5.
Greenfoot Game Programming Club.
CSCI/CMPE 4341 Topic: Programming in Python Review: Exam I Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
1 CS161 Introduction to Computer Science Topic #9.
Algorithms Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Copyright © 2006 by Maria Litvin, Gary Litvin,
1 Printing in Python Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external files.
Repetition Control Structure. Introduction Many applications require certain operations to be carried out more than once. Such situations require repetition.
Chapter 2 – The Little Crab Program:. Little Crab Scenario Inheritance: The Arrows Denote Hierarchy Crab is an Animal Animal is an Actor Therefore, It.
The Concept The Triangle Inequality Theorem states that any two sides of a triangle when added together will always be larger than the third. EX:
Improving the Crab Mrs. C. Furman August 19, 2010.
English Language Arts 7 Paragraphs “The Writing Process”
Adding and Eating Worms Mrs. C. Furman August 23, 2010.
Programming Languages Dan Grossman 2013 ML Expressions and Variable Bindings.
Review for Test 2 Chapters 5 (start at 5.4), 6.1, , 12, 13, 15.1, Python.
Selection Statement Chapter 3. A Java Language Program Is a Class A Class has data declarations and methods A Method has statements or instructions to.
Chapter 4 - Finishing the Crab Game
Chapter 4 - Finishing the Crab Game
Chapter 9: Value-Returning Functions
Chapter 10 Programming Fundamentals with JavaScript
Functions Chapter 5 CS12 - Computer Programming 1 Chapter 5.
Chapter 3 – Improving the Crab Game
GC211Data Structure Lecture2 Sara Alhajjam.
Review: Chapter 5: Syntax directed translation
Functions Chapter 6-Part 2.
The Selection Structure
JavaScript Syntax and Semantics
Control structures Chapter 3.
Introduction to Object-oriented Program Design
CS190/295 Programming in Python for Life Sciences: Lecture 1
The Little Crab Scenario
Chapter 10 Programming Fundamentals with JavaScript
Control Structures: Selection Statement
Defining Class Member Data/characteristics
Coding Concepts (Basics)
Pages:51-59 Section: Control1 : decisions
Object-oriented Design in Processing
Chapter 6: Repetition Statements
Classes and Objects Still Chapter 1.
Programs as Directions
Workshop for Programming And Systems Management Teachers
Chapter 9: Value-Returning Functions
ICT Gaming Lesson 3.
Final Review Bina Ramamurthy 4/5/2019 BR.
Methods, Data and Data Types
Greenfoot November 8, 2009.
Final Review Bina Ramamurthy 4/15/2019 BR.
Control Structures: Selection Statement
Pages:51-59 Section: Control1 : decisions
1.7 A Second Example.
Review Lab assignments Homework #3
CIS 136 Building Mobile Apps
Dasar-Dasar Pemrograman 2: Java Basics
The return Statement © 2018 Kris Jordan.
Presentation transcript:

Adding Behaviors (methods) Chapter 3

A Java Language Program Is a Class A Class has data declarations and methods A Method has statements or instructions to perform the function of the method Statements can be: Sequence statement; Ex: assignment statement Selection statement; Ex: if statement Repetition statement… we will learn it later It is similar to a writing an essay in any language: Chapters, paragraphs, sentences, etc.

Sequence Statement Assignment statement; Syntax: (structure, format) LHS = RHS; Data = value; Example: gunReloadTime = 5; Semantics: (meaning) Assign gunReloadTime the value of 5

Selection Statement Implementing choices in the design Syntax: if (condition) { // do something } else { // do something else

Condition How to express / write in Java language the condition for the selection statement? Using relational operators: < > <= >= == !=

Implementing Random Behavior Using random numbers generated by the Greenfoot environment. How to get a random number from the Greenfoot environment? Greenfoot itself is a class. Invoke a class method getRandomNumber (range) Example: percent = Greenfoot.getRandomNumber(100); percent will be assigned a random number between 0-99.

Adding new methods Lets add methods: turnAtEdge() randomTurn() lookForWorm() Lets add also eatWorm() Lets look at the methods that Greenfoot offers Lets add sound …. Lets stop the Greenfoot when a certain condition is met

10 Concepts Sequence statement Selection statement Method call Method definition Parameter passing Greenfoot methods (ex: getRandomNumber(range)) Adding sound (playSound(“xyz.wav”);) Stopping the Run Other methods in World Class and Actor class Adding comments // as well as /*… */