![]() ![]() ![]() That means that any method that has a Void return type do not give any information, they just do their action and then stop. The word Void means “nothing” in this context. This tells us what the method will return to us when we invoke it. The method also has some information about what kind of data goes in to the method call and what data comes out of it. Just using those two methods, void move () and void setDirection(int direction) set up four of your Wombats to look like this: What happens when you choose different numbers (0~3)? Lastly try void turnLeft(). What does the Wombat do? Now try void setDirection(int direction). You invoke a method by choosing it from the menu. ![]() These operations are called methods in Java. The object menu lists all the things that the object can do. Now that we have made a bunch of objects we can make them do something by right-clicking them. Move your Wombat picture in to the world by clicking anywhere in the world.ġ.1 TRY THIS! Make a bunch of Wombats and leaves and bring them in to the world.ĭoing stuff with Objects ( invoking a method) Right click on the Wombat class and then the class menu will pop up.Ĭhoose the option at the top of that menu, new Wombat(), and it will make new Wombat objects. When we have a class in Greenfoot, we can create objects from it.You can call an object an instance if you want, in programming they just mean the same thing. Think of it this way, if you had a class called transportation it would include a lot of stuff like trains, planes, boats, roller skates, skateboards, bicycles, cars, trucks…… But if you had a class called skateboards it would have long boards and short skateboards and mini-skateboards, but it would not have any monster trucks in it. ![]() For example, class Wombats stands for all Wombats. A class means something that stands for all of the things that belong to it. Since Java is an object-orientated language, it uses objects and classes. They are World, WombatWorld, Actor, Leaf, and Wombat. The three parts are: the World: where the programs will run, and you can see stuff happen, the class diagram: this is where the world and actor classes are, the execution controls: Act, Run, Reset and the speed slider. To see this, start up Greenfoot and click on Scenario in the top left, then choose open and navigate to the leaves-and wombats scenario. Scenarios are programs that do something. The Greenfoot interface is what we see when we create a scenario or load a scenario in to Greenfoot. Greenfoot: an interactive Java environment. Topics: What we are going to talk about: Greenfoot, the Greenfoot interface, doing stuff with objects (interacting), invoking methods, running a scenarioĬoncepts: (ideas you should know at the end of the lesson) object, class, method call, parameter, return value Answer questions in point form, screencap results and code. Whatever the number (800, 600, 2), it is the number of possible returns, starting at zero and ending at one less than that number.Make a word doc, define in your own words everything in bold. The 800 (which is the width of the world) and the 600 (which is the height of the world) ensure that what is returned will be somewhere in the world. (3) x and y, here, will be used to place a star in the world. The last statement will 'wrap' the star around the world: if on left edge, set the next x to at the right edge. That just makes each star move twice its speed. For some reason (or for no reason) this code is adding speed to the x location twice once in the 'x =.' statement and once in the 'setlocation(.' statement. (2) this is the part of the code that moves the star. The next line creates an image with that size and two lines later the circle (oval) drawn on the image also uses it as the diameter of the star. It is not really being used as a radius, but as a diameter here. Radius is actually the size of the star (in pixels). ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |