CS 111 - Fall 2012

Exam 1 Solutions

Note that for the write code questions, the web page removes the indentation originally given to the code.

  1. B
  2. D
  3. C
  4. E
  5. E
  6. E
  7. C
  8. D
  9. B
  10. A
  11. B
  12. D
  13. A
  14. D
  15. C
  16. B
  17. E
  18. B
  19. D
  20. E
  21. Picture p;
    p = new Picture(640, 480);
    Turtle t;
    t = new Turtle (p);
    int count;

    t.setPenColor (Color.BLUE);

    count = 0;
    while ( count < 4)
    {
    t.forward (50);
    t.turn (90);
    count = count + 1;
    }

    t.penUp();
    t.forward (100);
    t.penDown();

    t.setPenColor (Color.RED);

    count = 0;
    while ( count < 4)
    {
    t.forward (50);
    t.turn (90);
    count = count + 1;
    }

    p.show();

  22. // Start a new method
    public static void drawDodecagon (Turtle tParam, int len, Color c)
    {
    Color temp = tParam.getPenColor();
    tParam.setPenColor (c);
    int count;
    int sides;

    sides = 12;
    count = 0;
    while ( count < sides)
    {
    tParam.forward (len);
    tParam.turn (360/sides);
    count ++;
    }

    tParam.setPenColor (temp);
    } // end of the new method
Topic attachments
I Attachment Action Size Date Who Comment
Java source code filejava Exam1Q2122.java manage 1.6 K 2012-10-23 - 16:25 UnknownUser  
Topic revision: r1 - 2012-10-23 - 16:25:39 - 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