CSCI 201 Fall 2003

Programming Project 4

Overview

In this assignment, you will work a modified version of problem 6.16 on page 377 of your text. The problem asks you to use the fillPolygon() method in the Graphics class to draw 10 stars. To make the job more easier, you will be given a class called PolyStar that can be used to calculate the coordinates needed to specify a star. The class is described below. Using PolyStar, you can not only vary the size and location of a star, but you can also create stars with different numbers of points. Below is a display of four stars created with the help of the methods in the PolyStar class.

Your Assignment

Your assignment is to write an applet named Star that creates 10 or more stars with the following characteristics:

  1. The locations of the stars must vary---no two stars can fall completely on top of each other. Make sure that all stars are largely visible within the area specified by Star.html.
  2. The radius specifying the size of each star must vary---not all ten stars can have exactly the same radius.
  3. The number of points for each star must vary---not all ten stars can have exactly the same number of points.
  4. The color of each star must vary---not all ten stars can have the same color.

The PolyStar class

The PolyStar class is provided on this link. When a PolyStar object is created, the following information must be specified:

  1. The x and y coordinates of the center of the star; see the figure below.
  2. The radius of the star (i.e., the radius of the outer circle as shown in the figure below).
  3. The number of points.
More information regarding the PolyStar class constructors is provided in comments in the code.

Once a PolyStar object has been created, the method getPerimeterPoint() can be used to determine the x and y coordinates that are input to fillPolygon() when drawing the star. The method requires as input a position number representing a position on the star's perimeter and returns a Point object containing the x,y coordinate of that position. The position numbers for a 6-point star are shown below.

Position numbers always begin with zero, and the starting position is always located on the outer circle as shown above. Position numbers correspond to points of slope change on the perimeter of the star. The coordinates returned by getPerimeterPoint() are in the form of a Point object. An Example of a call to getPerimeterPoint() is:

   PloyStar star1 = new PolyStar(100, 100, 80, 5);

   // get the coordinates of point 0 on the outer circle
   Point position0 = star1.getPerimeterPoint(0);  

You will find it useful (but not required) to use getPerimeterPoint() to acquire the x and y coordinates (stored in a Point object) that must be input to fillPolygon() when drawing a star.

Programming Style

Note that 10% of your program grade is based on the readability of your program. This includes things like proper indentation, comments, and the naming of variables and methods as described in the style guide for this class. To receive full credit for your program, make sure that you use proper indentation as demonstrated in your text and in class room examples. Also include comments at the top of each program stating your name, the course, and the purpose of the program: For example:

/*
** Name: your name here 
** 
** Course: CSCI 201 
** 
** Purpose: purpose of program here 
*/

Submitting Your Program

The program written for this assignment must be turned in by transferring the java source code file and the HTML file to your ftp directory for this class. Both the source code file (i.e., Star.java) and the HTML file (Star.html) should be turned in and the files must have exactly those names. You were shown how to transfer files to your class ftp directory in lab 1.