Change Contents of the Bubble
View this PageEdit this PageUploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Pre-Quiz1-Summer 2007

Pre-Quiz1-Summer2007.pdf

(1) Who is your grading TA? (Please circle one)
      Kristin      Rory

(2) Which of the following lines of Java code are POSSIBLY valid?
      (a) integer i = 0;
      (b) int i = 9;
      (c) int i;
      (d) i = 9;
      (e) int integer = "Hello world";

(3) The following function goes through all the numbers from 1 to 10, adding them together and returns the sum. Complete the first line of the for loop so that the function works correctly.
int sum10() {
   int total = 0;
   for (_____________ ; _________________________; _________________) {
      total = total + i;	
   }
   return total;
}

(4) The following method in the class Picture decreases the green in the picture (and therefore makes it look more magenta). It contains some syntax errors in the Java code. Correct the errors.
function void decreaseGreen() {
   Pixel[] pixels =  self.getPixels();
   width = this.getWidth();                 
   int height := this.getHeight();
   int area = width x height;
   int pixNum = 0;
   while (pixNum <= area):
      Pixel pix = pixels(pixNum);
      greenValue = getGreen(pix);
      pix.setGreen((int)(greenValue * 0.5));
      pixNum = pixNum++;
}

(5) Use the following code to help you with the following questions:
public class TurtleSquare{
  public static void main(String [] args){
    Picture canvas = new Picture(500,500);
    Turtle t = new Turtle(canvas);
    
    t.penDown();
    for (int i = 0; i < 4; i++){
      t.forward(100);
      t.turn(90);
    } 
    canvas.show();
  }
}


Version A:

The bigger box is 100 by 100 Pixels. The smaller box is 50 by 50 Pixels

Write Java code that creates the picture shown above.

public class TurtleSquaresA{

   public static void main(String[] args) {

      // Write your code here

   }
}


Version B:
Uploaded Image: TurtleSquares.JPG
All boxes are 100 by 100 Pixels.

Write Java code that creates the picture shown above.

public class TurtleSquaresB{

   public static void main(String[] args) {

      // Write your code here

   }
}



Questions? Answers? Post them on Pre-Quiz 1-Summer 2007 Questions

Links to this Page