CSCI 201 Spring 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 randomly sized and located stars. To make the job more fun, you will be given a class called PolyStar that can be used to calculate the coordinates needed to specify a star. 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 5 or more stars with the following characteristics:

  1. The locations of the stars are randomly selected; make sure that all stars are largely visible within the area specified by Star.html.
  2. The radius specifying the size of each star is randomly selected to be between 25 and 125 inclusive.
  3. The number of points for each star is randomly selected to be between 5 and 10 inclusive.
  4. Each of 5 stars is a different color, and then you may repeat colors.

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 methods getOuterPoint() and getInnerPoint() can be used to determine the x and y coordinates that are input to fillPolygon() when drawing the star. Each method takes a point number representing a point on the star and returns a Point object containing the x,y coordinate of that point. The point numbers for a 5-point star are shown below.

Point numbers always begin with zero. They correspond to points of slope change on the perimeter of the star, and they lie along either the inner or the outer circle, as shown above. The method getOuterPoint() returns the coordinates of points on the outer circle while getInnerPoint() returns the coordinates of points on the inner circle. In both cases, the coordinates are returned in the form of a Point object. An Example of a call to getOuterPoint() and getInnerPoint() is:

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

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

   // get the coordinates of point 0 on the inner circle
   Point Innie  = star1.getInnerPoint(0);

You will find it useful (but not required) to use the getOuterPoint() and getInnerPoint() methods to acquire the x and y coordinates that are 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. 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 a comment at the top of each program stating your name, the course, and the purpose of the program:

// 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