CS116      Lab 1 - Objects and Methods

Objectives:

  1. Before starting this lab you should have read chapter 3 in your text.
     
  2. Open Eclipse and import the cs116 project. 
     
  3. In Chapter 3 you should have read about creating objects by using Class objectName = new Class(parameterList);
    Create a World object and a Turtle object in that world by typing the following commands in the Interactions Pane:

    World worldObj = new World();
    Turtle turtle1 = new Turtle(worldObj);

    You should have a frame containing your world with a turtle in the middle.
     

  4. 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. 
     

  5. 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.
     


  6.  

    Assignment:
    Write a Turtle method which draws an equilateral triangle.  The method should take a parameter which is the length of the sides. 


     


  7.  

    Assignment:
    Write a Turtle method which draws your initials.  An example would be:

    /**
     * Method to draw my initials
     */
    public void drawInitials(){

      // CODE GOES HERE...
    }


     


  8.  

    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. 

     

  9. Email your modified code MyProgram.java and Turtle.java to me at jill.zimmerman@goucher.edu