Lab 6: Iteration, Random Numbers, User Input

Purpose

The purpose of this in-lab is to (1) give you more experience with iterative constructs, (2) illustrate how random numbers can be used to enhance a program and (3) learn to do error checking when taking input from a user.

Partners

You are encouraged to work with one other partner on this assignment.

Preliminaries

Create a BlueJ project named lab6 on your lab computer. Place the following files into this project:

Assignment

Modify the DrawEllipses class so that it produces the desired number of ellipses. The largest ellipse should touch each edge of the drawing surface. The ellipses should be nested one inside of the other at uniform intervals. The color of each ellipse should be randomly determined. All ellipses should be drawn with the fill method.

Modify the Canvas class so that if the user enters a negative integer, the program continues prompting the user for an integer until a non-negative integer is entered. Other types of user errors do not need to be handled.

Submission

Before your lab section finishes, e-mail your lab TA the Canvas.java and DrawEllipses.java files in an e-mail with the following subject line: CS 160, Lab 6, your name, your partner's name.

Grading - 20 points possible

To receive credit for this assignment, your lab TA must receive an e-mail (with a timestamp before your lab section ends) from you with the appropriate files attached to it. Do not worry if you are not finished - send what you have because partial credit can be earned.

Helpful Hints

Before Lab Ends

Once you have e-mailed your lab TA the appropriate files, please delete the Lab6 directory that you created and empty the recycle bin on your desktop. Thanks.

Valid XHTML 1.0!