Change Contents of the Bubble
View this PageEdit this PageUploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Midterm exam 1 review Fall2005: Making Boxes with Turtles

Back to Midterm Exam 1 Review Fall2005

Questions? Answers? Comments?



public class TurtleBoxes {
  
  public static void main(String [] args){
    Picture canvas = new Picture(500,500);
    Turtle fred = new Turtle(canvas);
    
    for (int i = 0; i < 4; i++)
      {fred.forward(100);fred.turn(90);}
    
    for (int i = 0; i < 4; i++)
      {fred.forward(150);fred.turn(90);}

    for (int i = 0; i < 4; i++)
      {fred.forward(200);fred.turn(90);}
 
    canvas.show();
  }
}


I played around with this code, cause I wasn't sure what 'i' needed to be used, but I found that only muliples of 4 seem to work. Why is that?
Student159

here is what i did.
public class threeBoxes {
  
  public static void main(String [] args){
    Picture canvas = new Picture(600,600);
    Turtle krista = new Turtle(canvas);
    
    for (int i = 0; i <= 3; i++)
      {krista.forward(100);
       krista.turn(90);}
    
    for (int i = 0; i <= 3; i++)
      {krista.forward(150);
       krista.turn(90);}

    for (int i = 0; i <= 3; i++)
      {krista.forward(200);
       krista.turn(90);}
 
    canvas.show();
  }
}


I also tried yours, betsy, and got the same results. i am assuming either one will work.

Removed at KS request

<=3 and <4 is the same thing – think about it. Why it has to be four times is a great story – ask me on Monday! It's called "The Total Turtle Trip Theorem," and it's why a circle is a 360-agon. Hint: Try to make a triangle with a turtle. Mark Guzdial



Link to this Page