Answer:

The completed applet is given below.

Ten Red Circles JApplet

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 javax.swing.JApplet;
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 JApplet
{
  final int width = 300, height = 150;

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

    int count =  0 ;
    while (  count < 10  )
    {
      int diameter = width/10;

      int X = count*diameter;           // the left edge of each square
      int Y = height/2 - diameter/2;    // the top edge of the squares

      gr.drawOval( X, Y, diameter, diameter );
      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 we used is a bit tedious. If you got lost, go back and review. Or just move on. Although arithmetic like this is typical of graphics programming it is not important that you work through every detail of this example.

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?