CS 101 - Fall 2011

Exam 1 Solutions

  1. a
  2. c
  3. b
  4. d
  5. b
  6. e
  7. c
  8. c
  9. a
  10. b
  11. b
  12. c
  13. a
  14. d
  15. c
  16. d
  17. a
  18. b
  19. d
  20. e

  21. World w = new World();
    Turtle t = new Turtle (w);
    int count;
    
    //draw outer red square
    t.setPenColor (Color.RED);
    count = 0;
    while ( count < 4 )
    {
      t.forward (100);
      t.turn (90);
      count = count + 1;
    }
    
    // move to in square location
    t.penUp ();
    t.forward (25);
    t.turn (90);
    t.forward (25);
    t.turn (270);
    t.penDown ();
    
    // draw inner blue square
    t.setPenColor (Color.BLUE);
    count = 0;
    while ( count < 4 )
    {
      t.forward (50);
      t.turn (90);
      count = count + 1;
    }
    
    // show the drawing
    w.show ();
    

  22. public static void q22 (Turtle t, int len, Color c)
    {
      Color temp = t.getPenColor();
      t.setPenColor (c);
    
      int count = 0;
      while (count < 9)
      {
        t.forward (len);
        t.turn (720/9);  // this value is 80 degrees
        count = count + 1;
      }
      
      t.setPenColor (temp);
    }