CS 111 - Program Design I

Spring 2014

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

  21. public static void main (String[] args)
    {
    System.out.println("Begin Java Exection");
    System.out.println("");

    // step 1: create our world
    World w; // created the variable
    w = new World (); // allocated memory space for the object

    // step 2: create a turtle to live on the world
    Turtle t;
    t = new Turtle (w);
    t.setPenWidth(5);
    t.setPenColor(Color.BLUE);

    //Step 3: do something with the turtle
    int i = 0;
    while ( i < 4 )
    {
    t.forward (50);
    t.turn (90);
    i = i + 1;
    }

    // move to a different loction
    t.penUp ();
    t.forward (75);
    t.penDown ();

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

    // step Last: display/show the world
    w.show();

    System.out.println("");
    System.out.println("End Java Exection");
    }

  22. public static void drawStar ( Turtle tParam , int length , Color c )
    {
    int index;
    int numSides = 15;

    Color originalColor = tParam.getPenColor();
    tParam.setPenColor (c);

    index = 1;
    while ( index <= numSides)
    {
    tParam.forward (length);
    tParam.turn (720 / numSides);
    index = index + 1;
    }
-- Main.troy - 2014-03-13
Topic revision: r1 - 2014-03-13 - 18:11:38 - 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