Chapter One – Getting to Know Greenfoot

advertisement

P

rogrammig

O

ne

: Chapter One – Getting to Know Greenfoot

Topics: the Greenfoot interface, interacting with objects, invoking methods, running a scenario

Concepts: object, class, method call, parameter, return value

Chapter One Objectives : After completing Chapter One in the Greenfoot book, students will.. o become familiar with the Greenfoot graphical user interface o interact with Greenfoot objects o invoke Greenfoot methods o run a Greenfoot scenario

Instructional Procedures with Explanations o Begin page 4 – you are opening a scenario from a resource drive (network drive instructed by teacher). o The largest area covering most of the screen (a sand-colored grid) is called the world. This is where the program will run (work). Greenfoot is a type of programming that incorporates a graphical user interface. o The class diagram is the area on the right with the beige-colored boxes and arrows. The top rectangle in the class diagram is the name of the class, and the ones connected belong to that class. o The execution controls such as; Act, Run, and Reset buttons at the bottom make the program work.

Objects and Classes o The class diagram shows us the classes involved with this scenario. They are World,

WombatWorld, Actor, Leaf, and Wombat. o Java is the programming language used to create these objects and classes. o Each class contains information that is important to make it function properly. o Remember that many objects can be created from a class.

Interacting with objects o We invoke methods (allows us to interact with objects) by selecting them from the menu. We are making things happen in our scenario. o Note the following method..

 void move( ) – note the word void – means to do nothing or stop – it will return nothing from this method

Return Types o The word at the beginning of the method is called the return type o It tells us what the method will return to us. The word “void” returns nothing. It stops the method essentially. o If the return type is “int,” it returns an integer value. Integers are whole numbers. o If the return type is Boolean, it will only have two values; true or false.

Parameters o The other bit in the method menu is the parentheses after the method name. o The parentheses after the method name hold the parameter list. This tells us the method requires any additional information to make it run. o If the parentheses are empty the method does not expect anything to come into it. This means no information will be passed to it.

Greenfoot Execution o Execution means to run or work. The “act” command will execute Greenfoot programs.

Understanding Class Diagrams o The arrows show relationship to the class. The word subclass can also be used to show the relationship to the class it belongs to.

Source Code o Source code is the Java programming written to create our scenarios or programs. We can alter the source code to change the program. Source code is contained in the editor window.

Download