CS 101 - Fall 2010

Exam 1 Solutions

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

  21. World w = new World();
    Turtle t = new Turtle(w);
    int i;
    
    // draw a red square of size 100
    t.setPenColor (Color.red);
    i = 0;
    while ( i < 4 )
      {
       t.forward (100);
       t.turn (90);
       i++;
      }
    
    // move into the inside of the red square
    t.penUp();
    t.forward (10);
    t.turn (90);
    t.forward (10);
    t.turn (-90);
    t.penDown();
    
    // draw a blue sqaure of size 80
    t.setPenColor (Color.blue);
    i = 0;
    while ( i < 4 )
      {
       t.forward (80);
       t.turn (90);
       i++;
      }
    
    // show the drawing
    w.show();
    

  22. public static void drawQ22 (Turtle t, int len, Color c)
      {
       Color c2 = t.getPenColor ();
       int i = 0;
       int numSides = 12;
    
       t.setPenColor (c);
    
       // draw the dodecagon
       while ( i < numSides )
          {
           t.forward (len);
           t.turn (360 / numSides);  // 360/12 = 30
           i++;
          }
       t.setPenColor (c2);
      }