TWiki> CS101 Web>CS101Spring2012>S12Exam1Solutions (2012-02-28, Main.troy)
Solutions to the First Exam for CS 101 Spring 2012
1. C
2. A
3. D
4. D
5. C
6. E
7. A
8. B
9. B
10. C
11. A
12. B
13. A
14. D
15. C
16. D
17. A
18. D
19. E
20. E
21. Below is one solution
World w = new World ();
Turtle t = new Turtle (w);
int index;

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

// move to the right to draw second square
t.penUp();
t.turn (90);
t.forward (100);
t.penDown();

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

// display the world
w.show();

22. Below is one solution
public static void drawDecagon (Turtle t, int len, Color c)
{
Color saved = t.getPenColor ();
t.setPenColor (c);

int index;
index = 0;
while ( index < 10 )
{
t.forward (len);
t.turn ( 360/10 ); // 36 degree turn
index = index + 1;
}
t.setPenColor (saved);
}
-- Main.troy - 2012-02-28
Topic revision: r1 - 2012-02-28 - 19:37:33 - Main.troy

 Copyright 2016 The Board of Trustees of the University of Illinois.webmaster@cs.uic.edu WISESTHelping Women Faculty AdvanceFunded by NSF  