The Little Crab Scenario

Slides:



Advertisements
Similar presentations
Getting to know Greenfoot
Advertisements

Games and Simulations O-O Programming in Java The Walker School
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.
Greenfoot Asteroids Mrs. C. Furman August 16, 2010.
Chapter 1 - Getting to know Greenfoot Bruce Chittenden.
Test review. When? Monday 9/27 in class Know Greenfoot How many classes? Top-most classes? What does each button do? Lowest child class?
AlgoTutor Tutorial (3) Program Pad J. Yoo, S. Yoo, C. Pettey, S. Seo, and Z. Dong MTSU Computer Science Department Making the transition from the algorithm.
Games and Simulations O-O Programming in Java The Walker School
Chapter 5 - Making Music: An On-Screen Piano
Created by NW 2012 – please note all copyright on images used is property of copyright holder. Note: some of the more complicated descriptions are taken.
CSE 113 Introduction to Computer Programming Lecture slides for Week 4 Monday, September 19 th, 2011 Instructor: Scott Settembre.
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
CSE 113 Introduction to Computer Programming Lecture slides for Week 2 Wednesday, September 7 th, 2011 Instructor: Scott Settembre.
Chapter 1 - Getting to know Greenfoot
Comments in Java. When you create a New Project in NetBeans, you'll notice that some text is greyed out, with lots of slashes and asterisks:
CMP-MX21: Lecture 4 Selections Steve Hordley. Overview 1. The if-else selection in JAVA 2. More useful JAVA operators 4. Other selection constructs in.
Greenfoot Game Programming Club.
Lesson 1: Writing a program. Java Java is a programming language Computer cannot understand it, though it can be translated ( compiled ) so a computer.
Repetition Control Structure. Introduction Many applications require certain operations to be carried out more than once. Such situations require repetition.
Computer Science I Programming in Java (programming using Processing IN Java, using IntelliJ IDE) Classwork/Homework: copy your Processing projects over.
Lesson 2: Reading a program. Remember: from yesterday We learned about… Precise language is needed to program Actors and Classes Methods – step by step.
Introduction To Greenfoot
Chapter 2 – The Little Crab Program:. Little Crab Scenario Inheritance: The Arrows Denote Hierarchy Crab is an Animal Animal is an Actor Therefore, It.
Improving the Crab Mrs. C. Furman August 19, 2010.
Adding and Eating Worms Mrs. C. Furman August 23, 2010.
Chapter 4 - Finishing the Crab Game
Control Structures- Decisions. Smart Computers Computer programs can be written to make computers seem smart Making computers smart is based on decision.
Greenfoot.
Basic concepts of C++ Presented by Prof. Satyajit De
Topic 02: Introduction to ActionScript 3.0
Chapter 4 - Finishing the Crab Game
Appendix A Barb Ericson Georgia Institute of Technology May 2006
The eclipse IDE IDE = “Integrated Development Environment”
Great way to learn is by example so fire up Visual Studios C (at home make sure you custom install with C++ - no longer default) by Deborah R. Fowler.
John Woodward A Simple Program – Hello world
User-Written Functions
Content Programming Overview The JVM A brief look at Structure
Object-Oriented Programming Using Java
Appendix A Barb Ericson Georgia Institute of Technology May 2006
Chapter 3 – Improving the Crab Game
Debugging and Random Numbers
Engineering Innovation Center
Creating Games with Greenfoot
Learning Java with Alice 3.0 Game Design Kathy Bierscheid
Manipulating Pictures, Arrays, and Loops part 2
Chapter 4 LOOPS © Bobby Hoggard, Department of Computer Science, East Carolina University / These slides may not be used or duplicated without permission.
Java Programming with BlueJ
Organizing Memory in Java
Hands-on Introduction to JAVA
HAPPY NEW YEAR! Lesson 7: If-statements unplugged
Chapter 5, Conditionals Brief Notes
COMPUTER PROGRAMMING PYTHON
Tonga Institute of Higher Education
Introduction to TouchDevelop
Sridhar Narayan Java Basics Sridhar Narayan
CS139 October 11, 2004.
CPS120: Introduction to Computer Science
CISC124 Labs start this week in JEFF 155. Fall 2018
Adding Behaviors (methods)
IDE’s and Debugging.
Methods, Data and Data Types
Greenfoot November 8, 2009.
There many situations comes in real life when we need to make some decisions and based on these decisions, we decide what should we do next. Similar situations.
Running a Java Program using Blue Jay.
Barb Ericson Georgia Institute of Technology Oct 2005
C++ Basics CSci 107. A C++ program //include headers; these are modules that include functions that you may use in your //program; we will almost always.
Bishopston Comprehensive School
Workshop for Programming And Systems Management Teachers
Presentation transcript:

The Little Crab Scenario

Load it Up In: Greenfoot / scenarios / book-scenarios/ little-crab

should look like this

create a crab object

this corresponds to: new Crab( );

what can a crab do?

some behaviors move( ) boolean atWorldEdge( ) turn( angle ) canSee ( another Class ) Eat (another Class )

Invoking methods When invoked (calling a method), returns a TRUE or FALSE as supplied information Whenever you press a number on a keypad or remote control, you are invoking (calling on) a method. e.g. If (key_pressed () == 9 ) { display 9 on screen }

Exercise 1 turn (int Angle), when invoked with Angle number, it will turn We'll ask the turn method to turn the crab object 5 degrees.

Exercise 1 (2) Click the Compile button. If you've typed the statement correctly, you should see the message "Class compiled - no syntax errors" at the bottom of the editor window. If you get an error message instead, examine your code and the code in the screen shot above to make sure it looks EXACTLY the same as my code. Close the editor window and click the Run button (you may need to click the Compile button first). You should see the crab move across the screen and stop at the edge of the world. The statement that calls a method is call a method call. So, move(); is a method call. You must always include the round brackets after the method name and the semi-colon at the end of the line of code. Java is case sensitive, meaning Move(); and move(); are two different statements.

Exercise 2 Type the Java statement move(); into the act method of the Crab class To turn the Crab when it reaches the edge of the world, a decision needs to be made. Do you know how to do that?

If statements General form of an if statement If (condition) { //our condition is true instruction; } // if our condition is false, do something something; In plain English: If the condition is true, do instruction, otherwise do something.

activity3 Add an if statement into the act() method of the Crab class: public void act() { if (atWorldEdge()) { turn(10); } move();

note pairs of brackets public void? public void act( ) { // this is a behavior! // add behaviors here if ( atWorldEdge( ) ) // most complicated thing here { move(); turn( 10 ); // turn 10 degrees } move( ); Start of if block Most errors can be traced back two things: Semi colons missing at the end of statement; Curly brackets not closed. Remember: For every open { curly bracket you use, it must have one that closes it. } End of if block end act( ) behavior end class

brackets and semicolons brackets surround classes, methods, and if statements classes, methods and if statements don’t use semicolons everything else does

Methods - 2 forms public void act( ) { if ( atWorldEdge( ) ) turn( 10 ); } move( ); DEFINITION OR DECLARATION USE, CALL, OR INVOCATION

code! /** * This class defines a crab. Crabs live on the beach. */ import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot) /** * This class defines a crab. Crabs live on the beach. */ public class Crab extends Animal // definition statement { public void act( ) // this is a behavior! // add behaviors here if ( atWorldEdge( ) ) // most complicated thing here turn( 10 ); } move();

/. This class defines a crab. Crabs live on the beach /* This class defines a crab. Crabs live on the beach. */ public class Crab extends Animal // definition statement To be freely used what we’re designing what it’s part of

Summary We are adding code to the act( ) method methods = “behaviors” public void act( ) method “declaration” turn( 17 ); method “call” move( ); method “call” if statement with brackets