Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10Interacting with Objects1/16/2009Opening Discussion●Have you come up with any questions about the class since last time?●Minute essay responses:–Do I give A's?–What will we be doing with Excel?–Can you succeed in this class coming in with little knowledge of computers?–It was good to hear that my efforts on first-year move-in day have finally paid off.Greenfoot●Let's run Greenfoot and open up the Wombats scenario.●Greenfoot environment has several parts to it.–Shows a 2-D graphical display in the main area. –Elements that make things active at at the bottom.–List of different classes are on the right.Classes and Objects●Java is a class-based object-oriented programming languages. We write classes and those are the blueprints for making objects.●Greenfoot groups different classes: World, Actor, Others.●We can tell Greenfoot to make a new object from a class either with a right-click or holding shift.Methods●Classes have methods in them and these methods can be called on the objects of that class.●Right click on “wombatWorld” at the top to call a method on the WombatWorld object. Right click on one of the objects to call a method on it.●Methods can cause things to happen or give us back information.Parameters and Return Types●Some methods need extra information. This is passed in through parameters.–The setDirection method in Wombat needs to be told a direction.●Some methods give you back information.–The getLeavesEaten method in Wombat tells you how many leaves have been eaten.●The “signature” of a method begins with the return type then has the method name and an argument list in parentheses.Types●If you go through all the options on the Wombat when you right click you will see a number of different types.–int: for numbers that don't have fractions.–boolean: either true of false.–String: any text you want.–GreenfootImage and World: types specific to Greenfoot.●Other types include double and char.●Classes define types.Act and Run●At the bottom of the window is an area that has a few buttons. All the actors in Greenfoot have a method called act.●Clicking the Act button calls that method on all the actors.●Clicking Run will repeatedly call the act method.Member Data●Objects can hold information as well. These are called members.●You can look at what is stored by an object by selecting inspect from the right-click menu.●Arrows are drawn when members store other objects. In Java object types are often called reference types.Minute Essay●Do you have any questions about the topics we discussed
View Full Document