CS 111 - Fall 2013

Exam 1 Solutions

  1. A
  2. C
  3. D
  4. D
  5. B
  6. E
  7. C
  8. B
  9. A
  10. B
  11. B
  12. C
  13. A
  14. B
  15. B
  16. C
  17. D
  18. C
  19. D
  20. B

  21. public static void main (String[] args)
    {
    World w = new World ();
    Turtle t = new Turtle (w);
    int count;

    // draw blue square
    t.setPenColor(Color.BLUE);
    count = 0;
    while (count < 4)
    {
    t.forward (100);
    t.turn (90);
    count = count + 1;
    }

    // move turtle to the left.
    t.penUp();
    t.turn(-90);
    t.forward(200);
    t.turn(90);
    t.penDown();

    // draw red square
    t.setPenColor(Color.RED);
    count = 0;
    while (count < 4)
    {
    t.forward (100);
    t.turn (90);
    count = count + 1;
    }

    w.show();
    }

  22. public static void drawNonagon (Turtle t, int len, Color c)
    {
    Color origColor = t.getPenColor();
    t.setPenColor (c);
    int count;

    count = 0;
    while (count < 9)
    {
    t.forward (len);
    t.turn (360/9); // turn 40 degrees (360/numSides)
    count = count + 1;
    }

    t.setPenColor (origColor);
    }
-- Main.troy - 2013-10-15
Topic revision: r1 - 2013-10-15 - 14:25:02 - Main.troy
 
Copyright 2016 The Board of Trustees
of the University of Illinois.webmaster@cs.uic.edu
WISEST
Helping Women Faculty Advance
Funded by NSF