A good answer might be:

The completed applet is given below.

Ten Red Circles Applet

Here is the completed applet. Look over how the named values (constants and variables) were used in computing the values for X and Y.

import java.applet.Applet;
import java.awt.*;

// Assume that the drawing area is 300 by 150.
// Draw ten red circles side-by-side across the drawing area.
public class tenCircles extends Applet
{
  final int width = 300, height = 150;

  public void paint ( Graphics gr )
  { 
    gr.setColor( Color.red );

    int count =  0 ;
    while (  count < 10  )
    {
      int radius = (width/10)/2;      // the diameter is width/10

      int X      = count*(width/10);  // the left edge of each of 10
                                      // squares across the area
      int Y      = height/2 - radius; // the top edge of the squares

      gr.drawOval( X, Y, 2*radius, 2*radius );
      count = count + 1; 
    }

  }
}

Here is what the applet does:

Not all browsers can run applets. If you see this, yours can not. You should be able to continue reading these lessons, however.

The arithmetic used in this applet is a bit tedious. If you got lost, go back a few pages. Or just move on. Although arithmetic like this is typical of graphics programming it is not important that you work through every detail.

QUESTION 14:

Look at the statements inside of the loop body. Are there any that do exactly the same thing for each iteration of the loop?