CS 10: Introduction to Computer Programming

In-Class Examination 1

Closed-Book, 75 minutes, Winter 1998
 

General Instructions


Question  Value 
1  20 
2  20 
3  15 
4  20 
5 25
Total 100 

1. What is the value of variables i, j, and k at point A) and B) below?

2. In the applet skeleton below, interpret the int variables x (horizontal coordinate) and y (vertical coordinate) to be the coordinates of a point.  Complete the following skeletal applet so that it paints a filled square whose upper left corner is at coordinates (100, 100).  The square should be 100 X 100, and colored:  Assume that variables x and y already have values. 3. Convert the following sequence of Java statements to an equivalent sequence without for statements.  You may use while statements.   If this cannot be done, explain why. 4. Complete the following skeletal applet so that it computes, into a variable called sum, the sum of all numbers between 10 and 60 that are not evenly divisible by 2, 3, 5, and 7.  Output the value of sum somewhere on the applet using the drawString command. 5.  Complete the following skeletal applet so that it paints 2 triangular stacks of circles, as shown (on the monitor during the exam).  Each circle is 10 pixels in diameter and is separated by 2 pixels from the circles around it.  The triangles are identical except the left one starts at the left side of the applet; the right triangle starts at horizontal coordinate 200.  Each triangle has 15 rows.  The triangles are colored the same:  Circles in the same column have the same amount of red.  Each circle has no green and no blue.  The amount of red in a column is 255/15 more than the column to its left.  The leftmost column has no red.