Fundamentals of Computer Science II (CSC-152 99S)

Assignment 3: A Simple Drawing Package

Assigned: Friday, February 5, 1999
Due: Friday, February 12, 1999

In this assignment, you will build a number of objects that can be used in building interesting pictures. These include two basic graphics objects (circles and squares) and a drawing assistant that helps draw objects in interesting ways.

You may work in groups of up to size four.

Basic Graphics Objects

Create two classes, Circle and Square, representing circles and squares that can be drawn on the screen. Both classes should include a draw(int x, int y, Graphics g) method that draws the object centered at the given point in the given graphics object. Both classes should also include a setColor(Color newColor) method.

You should have two constructors for Circle. It is up to you what color the second constructor chooses. (It could always be the same; it could be random.)

The Circle class should also provide setSize(int newDiameter) and getSize() methods.

You should also have two constructors for Square. Once again, it is up to you what color the second constructor chooses.

The Square class should also provide setSize(int newSideLength) and getSize() methods.

A Drawing Assistant

Create a class, DrawingAssistant that can help draw interesting patterns with the basic graphics objects. This class should include the following methods:

drawOne(CircleOrSquare thing, int x, int y, Graphics g)
Draw the circle or square centered at (x,y)
drawSequence(CircleOrSquare thing, int n, int x, int y, int deltaX, int deltaY, Graphics g)
Draw a sequence of n circles or squares, starting at (x,y) and changing the center by (deltax,deltay) at each step.
drawConcentric(CircleOrSquare thing, int n, int x, int y, int deltaSize, Graphics g)
Draw a sequence of n concentric circles or squares, changing the diameter or side length by deltaSize each time.
drawRandom(CircleOrSquare thing, int n, Graphics g)
Draw n circles or squares at random positions on the screen.

It is likely that you will need to take advantage of overloading and create two versions of each method, one for squares and one for circles. If you read ahead, you are also permitted to take advantage of inheritance or interfaces, which we will discuss in class 10.

A Drawing Applet

Create an applet and corresponding HTML page that test your various methods.

Extra Credit

Pick something creative. For example, you might create a StickFigure class and extend DrawingAssistant to support it.

Turning It In

Turn in

Email me


Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.

This page may be found at

Source text last modified Tue Feb 16 10:25:43 1999.

This page generated on Tue Feb 16 10:27:45 1999 by SiteWeaver. Validate this page's HTML.

Contact our webmaster at