You must login or register to participate.

Description

Learn Java, the language of the internet!  No prior experience required!

To get started, JOIN THIS GROUP. Then click on the Activities tab. Next complete each of the Activities. And finally compete in the Challenge Activity.

Click the Details tab for more information. After you've completed this path, if you've enjoyed it and want to go further, check out some of the other programming learning paths, including Make a 3D Video Game and Building Flashy Websites with JavaFX.

Learning Path and Challenge Activity Provided By

FreshBrain is proud to sponsor the "Learn Java Programming" learning path and challenge activity.

Let’s Make a Kangaroo

 Let’s Make a Kangaroo

Description

This activity will have you create a brand new actor class and add an object of that class using the Greenfoot IDE.  In this activity, you will:

  • Create a new class - Kangaroo and cut and paste code to give it content.
  • Compile your new class.
  • Create a new object of this class and add it to the wombatWorld
  • Modify some lines of the Kangaroo class, compile and add it to wombatWorld and see how the code changes affect behavior.

Skills you will learn include:

  • Being able to use the Greenfoot IDE to create a new Actor class.
  • Learn more about classes, objects and methods.
  • Learn some basic programming concepts and constructs.
  • Learn how to use Sun’s online Java programming manuals.

Basic Steps

  1. Start up Greenfoot.
  2. Make sure you have opened the Wombats scenario.  If not, click Scenario->Open… and select Wombats.
  3. Access the context menu (right-click on Windows, ctrl-click on Mac) on the Actor class located on the right side of the IDE. Select New Subclass... .  Name your new class  Kangaroo and select a image from category: animals: kangaroo and click Ok
  4. Right click on Kangaroo. You’ll notice that there is no new Kangaroo().  That’s because we need to add code for this class before we can create objects.  Instead, select open editor.  Just to make this simple, select all the code,  (click at the top and drag the mouse to the bottom of the existing code).  Then click the Cut button.  It will be easier to just replace all this code for this activity.
  5. Double click on class Wombat. Select all the source code (similar to what we did for Kangaroo), but this time click the Copy button.
  6. Go back to the editor for Kangaroo.  Click Paste.  We now have a copy of all the Wombat code in Kangaroo.
  7. But this is a Kangaroo, NOT a wombat.  From the editor for Kangaroo, select the menu Tools -> Replace… The find dialog will popup.  In the text area labeled find, type Wombat.  In the text area labeled replace, type Kangaroo.  Click Replace All  to replace all occurrences of Wombat with Kangaroo.
  8. Compile, add wombats, kangaroos and leaves and run the scenario.  We have created our first new class!
  9. At this point, please refer to the document Let's Make a Kangaroo - Digging Deeper.  The Digging Deeper document will contain some code that you will need top copy and paste into your program.  Open the Digging Deeper page in another tab or window, and continue with the following steps.
  10. To class Kangaroo, add method turnRandom(). Double click on class Kangaroo.  From the Digging Deeper document, copy the code for the turnRandom() method (the code will be displayed in a light blue box).  At the bottom of the Kanagaroo class, just before the final closing ‘}’ paste the turnRandom() code.
  11. In the method act(), change the call from turnLeft() to turnRandom().  This will cause your Kangaroos to turn in a random direction, while your Wombats will continue to always turn left.
  12. Compile, place objects and run scenario.  Note the differences in behavior between Wombat and Kangaroo.
  13. Read through the Digging Deeper document for details about the code changes you just made.
  14. Please read the following instructions for preparing your work prior to submission to this activity.
  15. Select Scenario -> Export.  Choose  Webpage (from Publish, Webpage, Application) and select a location to save the scenario as an applet (a jar file and a .html file).
  16. Submit the exported jar file for this activity.


Suggested Activity Tools

Resource Links

Recent Submissions

icon

Animal World

0
July 5, 2010 by JGardner13
icon

Now a kangarooWorld

0
January 22, 2010 by fireguy97
icon

Yet another Wombat World

0
December 19, 2009 by Fireater989
icon

Kangaroo World

0
September 27, 2009 by oddron
icon

Wombat Activity 2

0
August 16, 2009 by Ryanh423
icon

Excercise 2: Kangaroos

0
March 23, 2010 by Sesu745
icon

Now a kangarooWorld

0
January 22, 2010 by fireguy97
icon

Wombat and Kangaroo World

0
September 10, 2009 by cerpintaxt
icon

Kangaroo Scenario..again. =]

0
August 13, 2009 by rsosa
More Submissions

Activity Forum

Topic
Replies
Posted
Last Reply
8
Jul 14, 2009
by artjunkie360
1 year 25 weeks ago
1
Jul 3, 2009
by lightningbug
3 years 46 weeks ago