The first few problems below are ImageMaps (see lecture notes from Feb. 15).
For each such problem, you'll write a class that implements ImageMap
.
One method in this class, pixelColor
, is prescribed:
its name must be exactly
pixelColor
, it must take be public
and not
static
, it must take in two int
s, a Color
, and
an Object
in that order, and it must return a Color
. You
may want to write other methods of your own to help pixelColor
do its
job.
You should write an appropriate number of test cases (using
checkExpect
) for each
such method, preferably in a separate test class. Once all your methods have passed
all their test cases, write some test cases that call map
on various
images and an instance of your ImageMap class; for the latter, don't even try to do a
checkExpect
, but just show
the results.
Each problem below is an animation or game. In most cases, you'll write a class
(using the “Animation Class” template in BlueJ) for each animation,
with an associated test class that contains test cases for the event-handling
methods and any other helper methods you decide to write. If you want the animation
run in a particular way (e.g. with a particular initial world or particular
arguments to bigBang
), write a
testAnimation
method that calls bigBang
with the arguments you had in mind. Note: bigBang
doesn't
return anything useful, so don't bother trying to use
checkExpect
on it.
For each animation, be sure to follow the design recipe for animations.
For each method, be sure to follow the design recipe for methods.
Be sure to choose meaningful names for methods and parameters, and watch for opportunities to re-use methods you, I, or Dr. Stemkoski have already written.
Also turn in a log of how many errors of different kinds you encountered in the assignment, with brief comments describing each one ("mismatched parentheses" is self-explanatory, but more complex errors might need more description). You may do this using the PSP forms, or simply by keeping track in a text file or on paper and turning it in.
You are encouraged to do this in teams of two students; turn in one copy of the project with both names on it (in the README file or in comments in the Java source files). Even if you do the assignment without a partner, make sure your name is on it.
If the “Submit” button works on your installation of BlueJ, you can use that to package up the entire project and send it to me and Dr. Stemkoski. Or you can use “Create JAR File…” and either e-mail us the JAR file or upload it to Moodle.
(int)
casting technique described in animation 2, below.)map
.)Develop an animation (name the class HW2_1) with an image of your choice (I suggest a fairly small one, like a stick-figure) rotating at a particular place on a fixed background image, with another copy rotating in the opposite direction in another place on that background. Something like this.
Develop an animation (class HW2_2) in which a dot moves around the screen
according to a formula: after
t time steps, it should be at location
(100 + 50 cos(t/10), 100 + 30 sin (t/10)).
It should look something like this
(although that program was written in a different language, it's the same exercise).
Note: You'll need to use the Math.sin
and Math.cos
methods, and you'll need to convert doubles to ints using casting syntax.
For example, (int)3.2
evaluates to the int 3;
(int)(3.2+4.6)
evaluates to the int 7; and so on.
Note that (int)3.2+4.6
evaluates to the double 7.6; do you
understand why?
Replace the "magic numbers" 100, 50, 30, and 10 in the above formula with appropriately-named variables. Experiment with different values.
Develop an animation (class HW2_3) in which a dot alternates between locations
(20, 50) and (60, 50) once per second, against a fixed background.
You shouldn't need an if
statement to do this.
Develop an animation (class HW2_4) in which a dot moves randomly in the x dimension: at every clock tick, it moves left one pixel, or right one pixel, or not at all, each with probability 1/3.
Develop an animation (class HW2_5) in which an initial background image is gradually covered with dots: at every clock tick, a dot is added at a random location.
Develop an animation (class HW2_6) of a digital counter: the user should see the number of clock ticks so far as a decimal numeral, in 18-point blue font in the animation window..
Develop an animation (class HW2_7) that shows the current mouse coordinates as a parenthesized ordered pair, in 18-point blue font in the animation window. It should look something like this (again, that program was written in a different language, but it's the same exercise).
Develop an animation (class HW2_8) in which a dot moves randomly in both dimensions: at every clock tick, it moves left, right, or not at all in the x dimension, and also moves up, down, or not at all in the y dimension.
Develop an animation (class HW2_9) of a solid colored disk whose color changes with time and the mouse location: the mouse's x coordinate should control the amount of red, the y coordinate should control the amount of green, and the number of clock ticks so far should control the amount of blue.
Develop an animation (class HW2_10) that starts with an image of your choice, and at every clock tick increases the green component of every pixel by 1 (but not going beyond 255).
Develop an interesting animation of your own, using the techniques we've seen so far. Go wild.
Error log: /10
(I'm not grading on how many or how few errors you encountered,
only on whether you recorded them adequately.)
Programming: To save time and get you feedback more quickly, I probably won't grade all of the problems, but a selection of them. Each ImageMap requires writing a class with one or two methods, and each animation requires writing a class with two or more methods.
Following directions | /10 |
Writing contracts from word problems | /10 |
Choosing test cases | /10 |
Choosing names; readability | /10 |
Coding | /10 |
Code re-use and function composition | /10 |