Computer Science 15-100 (Sections T & U), Spring 2008
Homework 7c
Due: Tue 4-Mar-2008 at 3:00pm (online submission) and at class
(physical copy)
(no late submissions accepted).
- Be sure to include your name, your Andrew ID, and your section (T or
U) clearly on the top of each file in your assignment.
- Name your program and your methods exactly as indicated.
- You will have exactly one program:
- Hw7cGraphics.java -- this will contain all the questions
- Use well-named variables, proper indenting, reasonable commenting,
etc. Do not use magic numbers!
- Provide complete (but concise) test cases!
- Provide the UI exactly as indicated. File-based UI should not
include prompts.
- Submit printed solutions in recitation. Your
printed solutions must be identical copies of your emailed solutions!
- Show your work (for the non-programming problems). Correct answers without supporting calculations
will not receive full credit.
- Checkerboards
Write a method that takes a page and a bounding box and draws a
red-and-black 8-by-8 checkerboard (with a red square in the top-left) that
fills the given bounding box (fill it completely, so that the width of the
cells may differ from their height). If either the width or height of
a cell would be smaller than 2 pixels, do not draw the checkerboard, but
instead draw a single magenta rectangle filling the entire bounding box.
Using this method, draw two checkerboards -- one in the top-left and another
in the bottom-right quadrants of the window.
- Steelers Logos
First, write a method that takes a page, a color, a center point (cx,cy),
and a radius, and -- using the technique we covered in class -- draws a
single astroid (the type
of hypocycloid in the Steelers logo) in the given color that is just
contained by the circle with the given center and radius. Here is a
picture of an astroid drawn in this manner, with about 10 points on each
positive or negative coordinate axis:
Next, write a method that takes a page, a center point (cx,cy), and a
radius, and -- using your astroid-drawing method -- draws a Steelers logo
just contained by the circle with the given center and radius. Here is
a picture of a Steelers logo:
Note that you do not have to exactly color match (use built-in colors),
and you do not have to exactly match the font (but you should use a bold
font, at least), and you do not have to exactly place the "Steelers" string
(do an ok job, but we have not learned how to center or otherwise accurately
place strings, so "close" is close enough for this problem). This
assignment is about methods, loops, and conditionals, and not about
strings, so do not spend too much time perfecting how the string looks!
Finally, use this Steelers-logo-drawing method as follows:
- In the bottom-left quadrant of the window:
Draw a single Steelers logo, centered in the quadrant, as large as the
smaller of the quadrant's width and height (so the logo just fits into
the smaller of the two dimensions of the quadrant). If the
quadrant is too small to draw a reasonable Steelers logo, just draw a
single green astroid centered in the quadrant.
- In the top-right quadrant of the window:
Draw a 3-by-3 "checkerboard of Steelers logos", where the Steelers logos
replace the red squares in a standard red-and-black checkerboard (again,
with the red square -- now the Steelers logo -- in the top left).
If the quadrant is too small to draw this many reasonable Steelers
logos, each of them should be replaced with a single green astroid of
the same size. Don't worry if the quadrant gets too small to even
see these green astroids.
- Study your classmates mystery methods
In hw7b, you were asked to write mystery methods (describable in
English) and code snippets (for tracing). Here, you are provided with
these -- both yours and your classmates -- as an excellent opportunity to
study for the upcoming test. This exercise is peculiar in that the
answers are provided for you. WHAT TO TURN IN: A statement
(based on the honor code, and included as a comment just after your name at
the top of the program you submit) indicating how much time you invested in
this exercise. For this part of the assignment, each minute you invest
earns 2% of the credit, up to 100% for 50 minutes. Again, there is
nothing to submit beyond this statement of time invested.
Student-authored mystery methods are
here: Hw7c-students.zip
Carpe diem!