CS 111 - Program Design I

Exam 1 Solutions - Spring 2013

  1. d
  2. c
  3. a
  4. b
  5. c
  6. e
  7. c
  8. d
  9. b
  10. a
  11. b
  12. d
  13. d
  14. c
  15. b
  16. b
  17. d
  18. d
  19. a
  20. e
  21. // See code below - Note the wiki removes the indentation
// declare variables
World w = new World ();
Turtle t = new Turtle (w);
int counter;

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

// move turtle to position for blue square
t.penUp();
t.turn (-90);
t.forward (25);
t.turn (-90);
t.forward (25);
t.turn (180);
t.penDown();

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

// show the world
w.show();
22. // See code below - Note the wiki removes the indentation

public static void drawStar (Turtle tparam, int length, int thickness)
{
int counter;
int numSides = 9;

// save the current pen width and change to parameter
int tempthickness;
tempthickness = tparam.getPenWidth();
tparam.setPenWidth (thickness);

// draw the 9 sided star
counter = 0;
while ( counter < numSides )
{
tparam.forward (length);
tparam.turn(720/numSides);
counter = counter + 1;
}

// reset the pen's width to the original value
tparam.setPenWidth (tempthickness);
} // end of method

-- Main.troy - 2013-03-08

Topic revision: r2 - 2013-03-08 - 17:46:42 - 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