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!
- Be sure to include your name, your Andrew ID, and your section clearly on the top of each file in your assignment.
- Also on the top of each file, include a timesheet logging all
the time you spent on that part of the assignment.
You will not be graded on your number of hours, but this information
will be helpful to the course staff.
- For non-programming problems:
- Place all your solutions to the non-programming problems in a single file
named Hw5 (with whatever extension is appropriate for the format you choose,
such as Hw5.txt or Hw5.html, etc). You must use a one of these file
formats: plain text (txt), or RTF, or HTML, or Word (doc, not docx), or PDF.
No other file formats will be accepted.
- Show your work. Correct answers without supporting calculations
will not receive full credit.
- For programming problems:
- Place each solution in its own file named exactly as given below, and
with a class name that exactly matches the file name. So if the file
name is Hw5Foo.java, the main class in that file must be Hw5Foo.
- Use well-named variables, proper indenting, reasonable commenting,
etc.
- Restrictions:
- You may not use arrays or any classes or methods from java.util.*
(except Random and Scanner) in
this assignment.
- You may use any and all String methods, Character methods,
Math methods, Random methods, Scanner methods, and Graphics methods. You also are
not required to use loops or conditionals, though often there may be no
other practical means of solving these problems.
- What to submit
- Either one zip file, Hw5.zip, containing all your files (this is
preferred), or all the files as attachments to a single email (do not send
one email per file!). It is recommended
that you "cc" yourself in that email, too, just to confirm that you properly
sent the email.
-
Hw4 "Easter Egg"
- Painting More Flags
- Qatar
- Israel
- Guyana
- Simple Animation
- Simple Game
- Bonus/Optional:
Flag of Nepal
- Bonus/Optional:
Kepler's Polygons
- Bonus/Optional:
Another Simple Game
- 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.
- 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.
- 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.
- 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).
- Guyana
(file: Hw5FlagOfGuyana.java)
(larger
image with details)
- 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.
- 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.
- Bonus/Optional:
Flag of Nepal
Under the same conditions as above, paint the Nepali flag
Nepal
(file: Hw5BonusFlagOfNepal.java)
(larger
image with details)
- 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).
- 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!