Eine gute Antwort wäre:

Shift all the circles a little bit to the right.

Shifting Circles

The left edge of the leftmost circle is 0 pixels from the left edge. The right edge of the rightmost circle is 30 - 2*radius = 30 - 20 = 10 pixels from the edge. If every circle was shifted over five pixels, the drawing would be fixed. This can be done, by adding yet more arithmetic to the applet:

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

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

  public void paint ( Graphics gr )
    gr.setColor( Color.red );
    int radius = 10;
    int Y      = height/2 - radius; // the top edge of the squares

    int count =  0 ;
    while (  count < 10  )
      int X      = count*(width/10) + ((width/10)-2*radius)/2;
      gr.drawOval( X, Y, 2*radius, 2*radius );
      count = count + 1;

Here is what it outputs:

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

The arithmetic used in drawing these circles is getting somewhat messy. It is not, for example, very clear what the statement

int X      = count*(width/10) + ((width/10)-2*radius)/2;

does, even after it has been explained.


What general technique could be used to make the program more easily understood? (This is a thought question that may take some time to answer. Hint: what type of language is Java?)