CS 111 - Fall 2014
Exam 1 Soltions
- D
- A
- C
- D
- B
- E
- C
- A
- C
- A
- B
- E - (Answer C was also scored as correct - however, correct answer is 3.4)
- B
- B
- D
- B
- D
- C
- D
- B
NOTE: The answers for Q 21 and 22 lose indentation due to the way the wiki removed extra space characters.
Possible Answer for Q 21.
public static void main (String[] args)
{
Turtle t1;
World w1;
w1 = new World( );
t1 = new Turtle (w1);
// draw a red square
t1.setPenColor (Color.RED);
t1.turn (90);
t1.forward (100);
t1.turn (90);
t1.forward (100);
t1.turn (90);
t1.forward (100);
t1.turn (90);
t1.forward (100);
// move up away from the red square
t1.penUp();
t1.forward (50);
t1.penDown();
// draw a blue square
t1.setPenColor (Color.BLUE);
t1.forward (100);
t1.turn (90);
t1.forward (100);
t1.turn (90);
t1.forward (100);
t1.turn (90);
t1.forward (100);
w1.show();
}
Possible Answer for Q 22.
public static void drawDodecagon (Turtle t, int len, Color c)
{
Color originalColor = t.getPenColor();
t.setPenColor (c);
int i = 1;
while (i <= 12)
{
t.forward (len);
t.turn (360/12); // 360/12 => 30
i = i + 1;
}
t.setPenColor (originalColor);
}
-- Main.troy - 2014-10-21
Topic revision: r1 - 2014-10-21 - 14:14:21 - Main.troy