Methods, Data and Data Types

Slides:



Advertisements
Similar presentations
Overloading Having more than one method with the same name is known as overloading. Overloading is legal in Java as long as each version takes different.
Advertisements

JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
CSCI 160 Midterm Review Rasanjalee DM.
Getting to know Greenfoot
Translate, Rotate, Matrix Pages Function Function Definition Calling a function Parameters Return type and return statement.
Animation Mrs. C. Furman. Animation  We can animate our crab by switching the image between two pictures.  crab.png and crab2.png.
Chapter 2 - The First Program: Little Crab
Program: Little Crab Mr Gano.
Chapter 1 - Getting to know Greenfoot Bruce Chittenden.
Chapter 1 - Getting to know Greenfoot Acknowledgement: Michael Kolling & Bruce Chittenden.
Objects Interaction and Source Code Week 2. OBJECT ORIENTATION BASICS REVIEW.
Exam 2 Review. variable types boolean - true or false String - "hello" int - 14 double
Principles of Computer Programming (using Java) Review Haidong Xue Summer 2011, at GSU.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Greenfoot. Getting Started Open the Greenfoot download site: Select Greenfoot
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
Object Oriented Design: Identifying Objects
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Java Programing Basics COMP.
Chapter 1 - Getting to know Greenfoot
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Java Programing Basics COMP.
Chapter 6 Programming Languages © 2007 Pearson Addison-Wesley. All rights reserved.
Principles of programming languages 5: An operational semantics of a small subset of C Department of Information Science and Engineering Isao Sasano.
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
P Chapter 2 introduces Object Oriented Programming. p OOP is a relatively new approach to programming which supports the creation of new data types and.
Lecture 4. Greenfoot 1 Pablo Romero, Department of Informatics Greenfoot Programming simulations and games in Java.
Greenfoot Game Programming Club.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Lesson 1: Writing a program. Java Java is a programming language Computer cannot understand it, though it can be translated ( compiled ) so a computer.
CS100A, Fall 1998 Key Concepts 1 These notes contain short definitions of the basic entities that make up a Java program, along with a description of the.
Repetition Control Structure. Introduction Many applications require certain operations to be carried out more than once. Such situations require repetition.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Kakihijau.googlepages.com Introduction To Greenfoot Part-2.
Chapter 3 AS3 Programming. Introduction Algorithms + data structure =programs Why this formula relevant to application programs created in flash? The.
Variables  A piece of memory set aside to store data  When declared, the memory is given a name  by using the name, we can access the data that sits.
Object Oriented Programming and Data Abstraction Rowan University Earl Huff.
AP Java Ch. 4 Review Question 1  Java methods can return only primitive types (int, double, boolean, etc).
Chapter 2 – The Little Crab Program:. Little Crab Scenario Inheritance: The Arrows Denote Hierarchy Crab is an Animal Animal is an Actor Therefore, It.
CS100Lecture 61 Announcements Homework P1 due on Thursday Homework P2 handed out.
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 5 – Making Music: An On-Screen Piano (Part 1 – Using Loops)
Introduction To Greenfoot
Variables A piece of memory set aside to store data
Introduction to Object-oriented Program Design
Creating Games with Greenfoot
Chapter 2.
Chapter 4 Procedural Methods.
Chapter 6: Programming Languages
The Little Crab Scenario
Java Programming with BlueJ
Object-oriented Design in Processing
Introduction to Object-Oriented Programming with Java--Wu
Unit 3 - The while Loop - Extending the Vic class - Examples
Defining Class Member Data/characteristics
Object-oriented Design in Processing
CS139 October 11, 2004.
Classes and Objects Still Chapter 1.
Chapter 6: Programming Languages
Recap Week 2 and 3.
Chapter 7 Procedural Methods.
Code Refresher Test #1 Topics:
Adding Behaviors (methods)
Session 2: Introduction to Object Oriented Programming
Greenfoot November 8, 2009.
Introduction to Object-Oriented Programming
Object-oriented Design in Processing
Object-oriented Design in Processing
Presentation transcript:

Methods, Data and Data Types Chapter 1-3

Wombat and leafs Open up greenfoot WombatWorld scenario Lets reverse engineer Wombat class Lets look at methods and data of this class? How and where?

Java language syntax Comments: You can add comments to your program to explain the code // single line comment /* multiple line comment */ Constructor is a special method that has the same name as the class; it has no return value

Data Types Whole numbers: represented by : int Example: int numStudents; Real numbers, numbers with fractional components, floating point numbers: float, double float bodyTemp; double sizeOfAtom; double distanceToMars; Logic variable that holds true or false values: boolean boolean raining; // true or false

Wombat Class Wombat //data private int leavesEaten; private int direction; int x; int y; int rotation; World world; private GreenfootImage image; //methods Wombat() // constructor void act() boolean canMove() void eatleaf() boolean foundLeaves() int getleavesEaten() void move() void setDirection(int direction) void turnLeft()

Leaf Class Leaf //data int x; int y; int rotation; World world; private GreenfootImage image; //methods Leaf() //constructor

Interacting with the Objects We use the methods: The Class (super class) Actor provides the methods: void move() void turnLeft() boolean canMove() int getLeavesEaten() Void setDirection(int direction)

Editing the source code Right click on Class, click on Edit code Add code to the methods We will add to the constructor Rocket() gunReloadTime = 5;

The Crab Scenario Lets work on the Crab Scenario to learn more about object-oriented deisgn

10 concepts Method Method definition (in the code) Method call Parameters Sequence of instructions Assignment statement (assigning a value to a data) ; terminator Inheritance (OOP concept: Ex: Actor::Crab) Void return type If-statement (selection statement; expressing choices in execution)