INFO I211 Lab 5
100 Random Circles

Due date: See Oncourse Modules or Assignments
60 points
Revised 2013 Jan 31

Learning Objectives

  1. Develop proficiency in looping, with the while and for statements.
  2. Reinforce previous learning of the Random class and Java 2D drawing API.

Instructions

Prerequisites

Requirements

Design, write, and test two programs, each of which draws one hundred random circles. One program should use a while statement; the other, a for statement.

The circles should be placed at random locations, with random diameters and colors. Each circle should use two random colors: one for the fill (interior), and one for the stroke (circumference).

Each circle must fit entirely within the drawing window; however, circles may overlap.

image of circles
Sample Result

Hints

  1. Override the paintComponent method to draw on a panel, as in the Bullseye and Boxes examples (Lewis and Loftus, Listings 6.5–6.8).
  2. Use fillArc to color the interior of the circle, and drawArc to stroke the edge. See Lewis and Loftus, Figure 2.12. Remember that both of these methods describe the arc in terms of an enclosing rectangle. Fill before stroking — it looks better that way.
  3. Think carefully about the interaction between the randomly chosen location and radius of a circle. The circle must fit entirely within the visible drawing area. Consequently, if you choose the radius first, it will constrain the choice of location; if you choose the location first, it will constrain the radius.
  4. Your two programs should be nearly identical, except that one uses a for statement and the other uses a while statement.

What to Turn in

Through Oncourse Assignments, turn in the source code files for both versions (while and for) and two screenshots of the random circle drawings.

Grading Criteria

60 points total