Answer:
An answer is given below.
Loop Options
The loop is a counting loop. Each iteration of the loop will draw one red circle.
import javax.swing.JApplet;
import java.awt.*;
// assume that the drawing area is 300 by 150
public class TenCircles extends JApplet
{
final int width = 300, height = 150;
public void paint ( Graphics gr )
{
int count = 0;
while ( count < 10 )
{
count = count + 1;
}
}
}
There are many ways to fill in the blanks so the loop iterates 10 times, but usually it is best to have a counter that goes from 1 to 10, or from 0 to 9. Often the arithmetic in the loop body is easier when the loop counts from 0 to 9.
Now let us focus on drawing the circles. The idea is to draw 10 circles in a row, nicely spaced out across the screen.
QUESTION 11:
The applet's drawing area is 300 pixels wide. If there are to be 10 circles, how wide is the area which will be used for each circle?