Computer Science 15-100 (Sections S-V), Fall 2008
Homework 5
Due:  Thu 2-Oct-2008 at 11:59pm (email copy) and at Friday's class/recitation (identical physical copy)
(no late submissions accepted).


Read these instructions first!


  1. Hw4 "Easter Egg"
  2. Painting More Flags
    1. Qatar
    2. Israel
    3. Guyana
  3. Simple Animation
  4. Simple Game
  5. Bonus/Optional:  Flag of Nepal
  6. Bonus/Optional:  Kepler's Polygons
  7. Bonus/Optional:  Another Simple Game

  1. Hw4 "Easter Egg"
    It has come to our attention that some students are not carefully reading their CA's comments on graded homework assignments.  This is unfortunate.  The CA's put in significant effort to write helpful comments intended to provide you with a great learning opportunity.  Read their comments, think about them, respond to them, and you will become a better, more efficient, happier programmer.  Really!  In any case, to encourage you to at least glance at your CA's comments, we had them place an "Easter egg" in your graded hw4 submissions.  What is an Easter Egg (in this context)?  If you want, you may optionally read the Wikipedia "Easter egg (media)" article  that explains it.

    In this case, your CA placed a comment in your returned hw4 that says something like "egg = 213" (however, the actual number is different for each of you).  Now onto the problem...

    In a file named Hw5EasterEgg.java, write a program that takes no input and simply prints out your entire Easter Egg message (again, like "egg = 213", but with your specific number).  Yes, this is a very simple program -- the point is to encourage (ok, require) you to look at your CA's comments.  Please look at the other ones while you're at it.
     
  2. Painting More Flags
    Paint each of the following flags (one flag per Java file) using any methods in Graphics, except that you may not load any images.  You should use custom colors, matching the colors in the flags as closely as possible.  Also, your flags may not be fixed-sized, but rather they must entirely fill the window, even when the window is resized.  While the window's size may change, you may assume the window will be roughly "flag-shaped" -- you will not be graded on how your flags appear in, say, a tall thin window (which is not at all "flag-shaped").

    Note: All these flag images are from the very informational CIA World Factbook, which includes a flags-of-the-world page

    Also note:  For all these flags, you must use loops wherever they are appropriate.
     
    1. Qatar
      (file:  Hw5FlagOfQatar.java)
      (larger image with details)
      Note: The black border around this image is not part of the image  (and so you should not draw it) -- it is included here only to distinguish the white in the flag from the white background of this file.
      Also note:  you can draw this with one white rectangle and one brown-ish polygon.  Use a loop to add the points to the polygon.
       
    2. Israel
      (file: Hw5FlagOfIsrael.java)
      (larger image with details)
      Note: Again, the black border around this image is not part of the image  (and so you should not draw it).
       
    3. Guyana
      (file:  Hw5FlagOfGuyana.java)
      (larger image with details)
       
  3. Simple Animation
    In a file named Hw5SimpleAnimation.java, write this Simple Animation.

    Note:  If this applet does not run in your web browser, you can try running this equivalent jar file:
       ballAroundSquare.jar

    Note that the blue box is the largest square you can draw with a 10-pixel margin around it (so you will take the minimum of the width and height when computing the size of the square), and that the circle pauses on the corners and is red while it pauses.
     
  4. Simple Game
    In a file named Hw5SimpleGame.java, write this Simple Game.

    Note:  If this applet does not run in your web browser, you can try running this equivalent jar file:
       simpleInvadersGame.jar

    Note that you move the blue paddle with left/right keys, and fire with the space bar.  The red ball is fired randomly (though always downward).  You should use bounding boxes for all collision tests (this makes the game a bit easier to implement).  Play the game in order to determine the rest of the design spec.
     
  5. Bonus/Optional:  Flag of Nepal
    Under the same conditions as above, paint the Nepali flag

    Nepal
    (file:  Hw5BonusFlagOfNepal.java)
    (larger image with details)
     
  6. Bonus/Optional:  Kepler's Polygons
    Among his lesser-known exploits, the great German mathematician and astronomer Johannes Kepler studied how polygons can tile the plan or portions of the plane.  As part of these studies, he created these interesting figures:

    In a file named Hw5BonusKeplerPolygon.java, paint any one or two of these four figures.  Note that the lower-left figure is worth half as many bonus points as the other three figures.  For this problem only, you do not have to make the figures scale according to the size of the window, but you do have to use loops as much as possible (which is an interesting conundrum) rather than manually place each polygon (which is less interesting).
     
  7. Bonus/Optional:  Another Simple Game
    In a file named Hw5BonusAnotherSimpleGame.java, write another game of your own design.  Make it complex enough to be bonus-worthy, yet simple enough to require 3-5 hours of your time.  Be sure to keep a timesheet!  Try to make it as attractive and as fun (both to write and to play!) as possible.  Be creative!

Carpe diem!