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

Midterm Exam 1 Review-Spring 2007: Make Turtle Boxes

Back to Midterm Exam 1 Review-Spring 2007

Questions? Answers? Comments?

Here's what I get: ~I'm assuming a picture of 600 x 600~
public class TurtleBoxes {
  
  public static void main(String [] args) {

	Picture canvas = new Picture(600,600);
	Turtle sam = new Turtle(canvas);
	
        sam.forward(200);
        sam.turn(90);
        sam.forward(200);
        sam.turn(90);
        sam.forward(200);
        sam.turn(90);
        sam.forward(200);
        sam.turn(90);
        sam.penUp();
        sam.forward(50);
        sam.turn(90);
        sam.forward(50);
        sam.penDown();
        sam.forward(100);
        sam.turn(-90);
        sam.forward(100);
        sam.turn(-90);
        sam.forward(100);
        sam.turn(-90);
        sam.forward(100);
   }
}
-Taylor

Can we use drawSquare() for this?

public class TurtleBox{

public static void main(String [] args) {

Picture canvas = new Picture(600, 600);
Turtle jenny = new Turtle(canvas);

for (int i =1; i <=4, i++) {

jenny.forward(200);
jenny.turn(90);}  //end of for loop

jenny.penUp();
jenny.forward(50);
jenny.turn(90);
jenny.forward(50);
jenny.turn(-90);
jenny.penDown();

for (int ind =1; ind <=4, ind++) {

jenny.forward(100);
jenny.turn(90);} // end of for loop


}
}
-Student527

I may have used the for loops a bit too much since I used one for doing something twice, but either way, this works...
public class TurtleBoxInBox {
  
  public static void main(String [] args) {
    Picture canvas = new Picture(600,600);
    Turtle jenny = new Turtle(canvas);
    for(int i = 0; i<4; i++)
    {jenny.forward(100);
      jenny.turn(90);}
    jenny.penUp();
    for(int i = 0; i <2; i++)
    {jenny.turn(-90); jenny.forward(50); }
    jenny.turn(-90); 
    jenny.penDown();
    for(int i = 0; i<4; i++)
    {jenny.forward(200);jenny.turn(-90);}
    canvas.show();
  }
  
}
-Student521



Link to this Page