Objectives:
World
worldObj = new World();
Turtle turtle1 = new Turtle(worldObj);
You should have a frame containing your world
with a turtle in the middle.
Chapter
3 discusses using objects by executing "methods". Look at the
documentation for the class Turtle. You will see that it "inherits"
from SimpleTurtle, meaning that it has all the methods of that class plus
special features of its own. Check out the methods available from
SimpleTurtle. We can use a method with
objectName.method(parameterList);
For example,
turtle1.forward(20);
moves the turtle forward 20 steps. Try out the methods
that move, and turn the turtle. Also try the methods penUp and penDown.
We can
define our own methods. On p57 of your text you are given a method for
the Turtle class which will tell the turtle to draw a square of any size
given by the parameter width. Open up the Turtle class and type
in this new method (including the comments which describe the method to a
human reader). Save your changes and try it out by telling the turtle
to draw a square of size 200. Use this same method again to draw a
square of size 50.
| Assignment: Write a Turtle method which draws an equilateral triangle. The method should take a parameter which is the length of the sides. |
| Assignment: Write a Turtle method which draws your initials. An example would be:
/** |
| Assignment: Edit MyProgram.java so that instead of printing a message it now, creates a World object, creates a Turtle object, and then the turtle draws your initials. |