CS 111 - Program Design I
Spring 2014
Exam 1 Solutions
- A
- D
- C
- C
- D
- B
- D
- B
- B
- C
- C
- D
- D
- B
- D
- B
- A
- A
- A
- E
-
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");
}
-
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