Computer Science 15-100 (Sections T & U), Spring 2008
Homework 5
Due: Fri 15-Feb-2008 at 10:00am (online submission) and at recitation
(physical copy)
(no late submissions accepted).




Also:
you must use "for" loops when appropriate. This includes a separate
"for" loop for each of the following (and perhaps others, too!):
* The diagonal pattern of 7 full and 2 half stars in
Bosnia and Herzegovina's flag (larger
image)
* The 14 red-and-white stripes in Malaysia's flag (larger
image)
* The 13 red-and-white stripes in the US flag (larger
image)
* The pattern of 50 stars in the US flag
* The many-toothed pattern (with 9 white points) in
Qatar's flag (larger
image)
* The makeStar method that is described below (for both
the 5-pointed and 14-pointed stars)
To do this, you will write additional static paint methods, one for each
quadrant of the window, like this:
public static void
paintBosniaAndHerzegovinaFlag(Graphics page, int left, int top, int width,
int height) {
// your code here!
}
public static void paintMalaysiaFlag(Graphics page, int left, int top,
int width, int height) {
// your code here!
}
public static void paintUSFlag(Graphics page, int left, int top, int
width, int height) {
// your code here!
}
public static void paintQatarFlag(Graphics page, int left, int top, int
width, int height) {
// your code here!
}
Note that the "width" and "height" in these signatures represent the
bounding regions for the given flag, and not the width and height of the
entire window! The main paint method will just call these paint
methods, providing appropriate arguments to place the flags in the
appropriate quadrant of the window, so your paint code will look like this:
public void paint(Graphics page) {
int width = getWidth();
int height = getHeight();
paintBosniaAndHerzegovinaFlag(page, 0, 0,
width/2, height/2); // top-left quadrant
paintMalaysiaFlag(....); // you fill
in the parameters
paintUSFlag(....);
// ditto
paintQatarFlag(....);
// ditto
}
Additionally, you must write one more static method that makes an
n-pointed star with exactly this signature:
public static
Polygon makeStar(int nPoints, int cx, int cy, int r1, int r2) {
}
This method will create and return a new Polygon that represents a star with
"nPoints" points, centered at the location (cx,cy), with an outer radius of
"r1" and an inner radius of "r2". You must use this method to create
the 5-pointed stars in Bosnia and Herzegovina's flag and the US flag, and
you must also use this same method to create the 14-pointed star in
Malaysia's flag.
Note: Do not use the Polygon.translate method this time -- instead,
make repeated calls to makeStar, one for each star in each flag.
Carpe diem!