Chapter 1 - Getting to know Greenfoot

Slides:



Advertisements
Similar presentations
Space Man Sam: Grammar Mistakes By Aleis Murphy Duke University, Under the direction of Professor Susan Rodger July 2010.
Advertisements

Mouse Tutorial for Win XP In this tutorial you will learn to: Move the mouse Click and double click Make selections Manage windows Use menus Click the.
Getting to know Greenfoot
Outlining the Action By Brisa Waechter. Usually sport or action shots are best but you can use any photo you like.
 Use the Left and Right arrow keys or the Page Up and Page Down keys to move between the pages. You can also click on the pages to move forward.  To.
Microsoft Word 2010 Lesson 1: Introduction to Word.
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.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Greenfoot Asteroids Mrs. C. Furman August 16, 2010.
Microsoft ® Office Word 2007 Training Table of Contents II: Customize your TOC [Your company name] presents:
Microsoft Office 2010 Access Chapter 1 Creating and Using a Database.
Wombats Creating Games with Greenfoot The Walker School – Games and Simulations
Chapter 1 - Getting to know Greenfoot Bruce Chittenden.
Chapter 1 - Getting to know Greenfoot Acknowledgement: Michael Kolling & Bruce Chittenden.
Mrs. Chapman. Tabs (Block Categories) Commands Available to use Script Area where you type your code Sprite Stage All sprites in this project.
Calvin and Hobbes Teach Properties and Functions Created by Daniel MacDonald under the direction of Professor Susan Rodger Duke University June 2013.
Fundamentals of Programming in Visual Basic 3.1 Visual basic Objects Visual Basic programs display a Windows style screen (called a form) with boxes into.
Alice Learning to program: Part Two by Ruthie Tucker and Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July 2008.
Mr. Wortzman. Tabs (Block Categories) Available Blocks Script Area Sprite Stage All sprites in this project.
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.
Working with Numbers in Alice - Converting to integers and to strings - Rounding numbers. - Truncating Numbers Samantha Huerta under the direction of Professor.
1 iSee Player Tutorial Using the Forest Biomass Accumulation Model as an Example ( Tutorial Developed by: (
by Chris Brown under Prof. Susan Rodger Duke University June 2012
Hello! Keep watching … I’ll show you how to use a mouse.
MICROSOFT WORD GETTING STARTED WITH WORD. CONTENTS 1.STARTING THE PROGRAMSTARTING THE PROGRAM 2.BASIC TEXT EDITINGBASIC TEXT EDITING 3.SAVING A DOCUMENTSAVING.
CIS—100 Chapter 15—Windows Vista 1. Parts of a Window 2.
PMS /134/182 HEX 0886B6 PMS /39/80 HEX 5E2750 PMS /168/180 HEX 00A8B4 PMS /190/40 HEX 66CC33 By Adrian Gardener Date 9 July 2012.
Greenfoot. Getting Started Open the Greenfoot download site: Select Greenfoot
How to construct an interactive PowerPoint.  The first task is always content, content, content.  What are the lesson objectives?  Remember Miller’s.
The Fundamentals of Using Windows 95. Windows 95 ã operating system that performs every function necessary for the user to communicate and control computer.
Alice 2.0 Introductory Concepts and Techniques Project 1 Exploring Alice and Object-Oriented Programming.
Teaching a character to walk in more than one world: Parameters and Inheritance. By Lana Dyck under the direction of Professor Susan Rodger Duke University.
Downloading and Installing Autodesk Revit 2016
Conditions. Objectives  Understanding what altering the flow of control does on programs and being able to apply thee to design code  Look at why indentation.
Microsoft ® Office PowerPoint ® 2003 Training Playing sound [Your company name] presents:
Animating Objects in Groups: Using Arrays and Lists By Ruthie Tucker under the direction of Professor Susan Rodger Summer 2008.
Lecture 4. Greenfoot 1 Pablo Romero, Department of Informatics Greenfoot Programming simulations and games in Java.
An Introduction to Alice (Short Version) – Extras! Yossra Hamid Under the Supervision of Professor Susan Rodger Duke University, June 2014 This is a continuation.
Downloading and Installing Autodesk Inventor Professional 2015 This is a 4 step process 1.Register with the Autodesk Student Community 2.Downloading the.
Greenfoot Game Programming Club.
Using Advanced Options Lesson 14 © 2014, John Wiley & Sons, Inc.Microsoft Official Academic Course, Microsoft Word Microsoft Word 2013.
Alice Learning to program: Part Two Writing Your Own Methods by Ruthie Tucker and Jenna Hayes Under the direction of Professor Susan Rodger Duke University,
Bunny Eat Broccoli Repetition – Simple loops and Conditional loops Susan Rodger Duke University July 2011.
The Essentials of Alice (Bunny) By Jenna Hayes under the direction of Professor Susan Rodger Duke University July 2008.
Illuminating Computer Science CCIT 4-6Sep
Lesson 1: Writing a program. Java Java is a programming language Computer cannot understand it, though it can be translated ( compiled ) so a computer.
Typing and Formatting a Research Paper WORD 2013.
Kakihijau.googlepages.com Introduction To Greenfoot Part-1.
Tutorial for Arrays and Lists. Description This presentation will cover the basics of using Arrays and Lists in an Alice world It uses a set of chickens.
Creating a 3D Interactive Story Prof. Susan Rodger Duke University July 19, 2007.
Lesson 2: Reading a program. Remember: from yesterday We learned about… Precise language is needed to program Actors and Classes Methods – step by step.
Kakihijau.googlepages.com Introduction To Greenfoot Part-2.
Word Create a basic TOC. Course contents Overview: table of contents basics Lesson 1: About tables of contents Lesson 2: Format your table of contents.
Introduction To Greenfoot
Database EssentialsDatabase Essentials Lesson 1 © 2014, John Wiley & Sons, Inc.Microsoft Official Academic Course, Microsoft Word Microsoft Access.
Summary Slide Printing Handouts Animations Slide Transitions Animate text Hyperlinks Action Buttons Adding sound to your PowerPoint presentationAdding.
Chapter 2 – The Little Crab Program:. Little Crab Scenario Inheritance: The Arrows Denote Hierarchy Crab is an Animal Animal is an Actor Therefore, It.
1.1: Objects and Classes msklug.weebly.com. Agenda: Attendance Let’s get started What is Java? Work Time.
VB.NET and Databases. ADO.NET VB.Net allows you many ways to connect to a database. The technology used to interact with a database or data source is.
Adding and Eating Worms Mrs. C. Furman August 23, 2010.
Chapter 4 - Finishing the Crab Game
Introduction To Greenfoot
Creating Games with Greenfoot
The Little Crab Scenario
Methods, Data and Data Types
Greenfoot November 8, 2009.
creating a ecosystems model in net logo
1.7 A Second Example.
Presentation transcript:

Chapter 1 - Getting to know Greenfoot Bruce Chittenden And modified by Mr. Lee

Start Menu | All Programs Greenfoot | Greenfoot

1.1 Getting Started Q:\ Assignments\ Mr. Lee\ Scenarios\ Copy “wombats” folder to “My Documents”. Open the scenario in Greenfoot.

Which leads to the question: “What are wombats?” Wombats are native Australian mammals.

The World: where programs will run, where we will see things happen. Class Diagram Execution Controls

Class Diagram: This is the little beige boxes and arrows on the right Class Diagram: This is the little beige boxes and arrows on the right. We’ll come back to them later. World Class Diagram Execution Controls

Execution Controls: includes the Act, Run, and Reset buttons, and the speed slider. More on them later. World Class Diagram Execution Controls

1.2 Objects and Classes We’ll discuss the Class Diagram first. It shows us the classes involved in this scenario. Here, we have 5 classes: World, Wombat World, Actor, Wombat, and Leaf. The classes World and Actor are will always be there – they come with the Greenfoot system. The classes are specific to the wombat scenario. They may be different or not exist at all in other scenarios. Let’s start by looking at the Wombat class. It stands for the general concept of a wombat. So this class describes all wombats. Once we have a class in Greenfoot (or Java), we can create objects from it.

Here’s how you create objects from the Wombat class. Try it out! Right Click on Wombat Drag to World Click New Wombat() You’ll get a small picture of a wombat object, which you can move around the screen with your mouse. Now place it in the World by clicking somewhere in the world. Once you have a class, you can create as many objects from it as you like.

Exercise 1.1: Create some wombats in the world. Make some leaves too.

There’s a shortcut to placing objects: shift-clicking into the world. Make sure the leaf class is selected, then hold down the Shift key and click into the world. What happens? Extra Credit: Make a journal entry in your notebook about worlds, classes, or objects.

1.3 Interacting with Objects Once we have placed some objects into the world, we can interact with these objects by right-clicking on them. The object menu will pop up. Right Click on the Wombat Invoke the Move method The object menu shows all the operations the object can perform (how the object can act). In this case, we see what the wombat can do. Two other functions, Inspect and Remove, will be discussed later.

Right Click on the Wombat In Java, these operations an object can perform are called methods. (Notice that they all end with parentheses.) We can invoke a method by clicking on it in the menu. Right Click on the Wombat Invoke the Move method Exercise 1.2: Invoke the move() method. What does it do? Try it a few times. Invoke the turnLeft() method. Finally, place two wombats into the world and make them face each other.

1.4 Return types void move() void turnLeft() Let’s look closer at the object menu. The move and turnLeft methods are listed as: We see more than just the method names. There is the word void at the beginning, and round brackets at the end. These are symbols that tell us what data goes into the method and what comes back from it. void move() void turnLeft() The word at the beginning is called the return type. It tells us what the method returns to us when we invoke it. The word void means “nothing” in this context: methods of void return type do not return any information. They just carry out their actions, and then stop.

Any word other than void tells us the type of information returned by the method. In the wombat’s menu we also see the return types: int – short for “integers” (what are some examples?) boolean – one only two possible values will be returned: “true” or “false” Methods with return type void are like commands for our wombats. If we invoke turnLeft(), the wombat turns left. Methods with any other return type are like questions: do what you have to do, but give us an answer when you’re done.

Consider the canMove method. When you invoke it, you will see a result similar to the one below. Here, the important information (data) is the word “true” returned by the method call. In effect, we just asked the wombat, “Can you move?” And the wombat answers, “Yes!” (true) Exercise 1.3: Invoke the canMove() method on any of your wombats. What does it usually return? Can you make the method return false?

Try out another method with a return value: Using this method, we can find out how many leaves this wombat has eaten. Int getLeavesEaten() Exercise 1.4: Create a new wombat and invoke the getLeavesEaten method. It will always return 0. Can you create a situation in which the method returns some positive number? Hint if you are stuck: Can you make the wombat eat some leaves?

1.5 Parameters The other bit in the object menu are the round brackets after the method name. The parentheses hold the parameter list, which tells us whether the method needs any information to run, and if so, what kind of info. If I tell you to jump, you would ask, “how high?” If the parentheses have nothing in between, e.g. turnLeft(), the parameter list is empty. In other words, it expects no parameters. The entire description of each method shown in the object menu, including the return type, method name, and parameter list, is called the method signature.

Let’s try out the setDirection method Let’s try out the setDirection method. We can see it has int direction as its parameter list, which tell us that the method expects one parameter of type int, which specifies a direction. Let’s invoke the method, and you will see the following dialog box. The comment near the top of the dialog box gives more details: the direction parameter should be between 0 and 3.

Exercise 1. 5: Invoke the setDirection(int direction) method Exercise 1.5: Invoke the setDirection(int direction) method. Provide a parameter value and see what happens to the wombat. Which number corresponds to what direction? Make a list on paper. What happens when you type a number greater than 3? How about a number that is a word (three) or not an integer (e.g. 2.3)?

1.6-1.9 Execution Controls Exercise 1.6: Place a wombat and a good number of leaves into the world. Then, invoke a wombat's act() method several times. What does this method do? How does it differ from the move method? Exercise 1.7: Still with a wombat and some leaves in the world, click the Act button in the executive controls near the bottom of the Greenfoot window. What does this do? Exercise 1.8: Add a few wombats to the world. What is the difference now between clicking the Act button and invoking the act() method on the wombats? Exercise 1.9 Click the Run button. What does it do?

Exercise 1.6

Exercise 1.6 Wombat Moves toward the Leaves

Exercise 1.6 Wombat Moves to Leaves

Example 1.7 Wombat Eats Leaf

Exercise 1.8

Exercise 1.8 The >Act Execution Control Affects All the Wombats

Exercise 1.9 Wombat Runs Around the Edge of the World

Exercise 1.9 act() method If we’re sitting on a leaf, eat the leaf Otherwise, if we can move forward, move forward Otherwise, turn left Leaves do nothing when called to act. The act() method is fundamental to Greenfoot objects. We will see it in every chapter. All Greenfoot classes/objects have this method.

Execution Controls, recapped The Act button is equivalent to invoking the act() method of every object exactly once. (Refer to the previous slide.) The Run button is equivalent to continuously clicking the Act button. You may have noticed that when clicked, the Run button becomes a Pause button, which can stop the whole show. The slider to the right of the buttons sets the speed.

A Brave New World You can erase objects from the world by right-clicking them and choosing Remove. But if the world becomes cluttered, and you want to start all over, there’s a shortcut: discard the world and create a new one. This is usually done via the Reset button. You will get a new, empty world. The old one has been discarded along with all objects in it – you can have only one world at a time.

Invoke a world method We have seen objects in the world have methods you can invoke via a pop-up menu. The world itself is also an object, with methods you can invoke. Above the world display is a title that shows the name of the world—”WombatWorld” in this case. Right-click this title to see the world’s menu.

One method is populate(). Reset the world, then try it out. Note the empty parameter list.

The other method is randomLeaves, which places some leaves at random locations in the world. Note the words in the parenthesis—called the parameter: int howMany It means you must supply additional information when you invoke the method. int means a whole number is expected, and howMany suggests that you can specify how many leaves to place in the world.

Invoke the randomLeaves method Invoke the randomLeaves method. A dialog will pop up asking for a value for the parameter. What would you enter to get the same number of leaves as the picture below?

1.8 Understanding the Class Diagram At the top of the diagram, you can see two classes called World and WombatWorld, connected by an arrow. The World class is in every Greenfoot scenario—it’s built-in. The class under it, WombatWorld in this case, represents the specific world for this scenario. The arrow shows an is-a relationship: WombatWorld is a World. We can also say that WombatWorld is a subclass of World.

Below the world classes, we see a second group of classes linked by an arrow. Each class represents its own objects. Reading from the bottom, we see Leaves and Wombats. Both are Actors in the world. Again, we have subclass relationships. For example, Leaf is a subclass of Actor. We can also say that Actor is a superclass of Leaf and Wombat. What is a superclass and what is a subclass in the diagram to the left? Animal Mammal Bonobo Human

1.11 Summary In this chapter, we saw what Greenfoot scenarios can look like and how to interact with them. We have seen how to create objects, and how to communicate with these objects by invoking their methods. Some methods are commands to objects, while other methods return information about the object. Parameters are used to provide additional information to methods, while return values pass information back to the caller. Objects were created from their classes.

Concept Summary