![]() |
![]() |
|
Due:
Feb.21 (Thu(!)) 14:00 accepted through Feb.21 24:00, due to power-failure; bring hardcopy to next class,
D2L and hardcopy.
Your submitted file should be named “hw04.rkt”, plus any .java files.
Standard instructions for all homeworks:
(This is the completion of hw04a, from D2L.) Consider the following information, which might be part of a sports-simulation:
A team is:
- a name (non-empty string), AND
- an offense rating (real number), AND
- a defense rating (real number).
(5pts) Give a data definition (including examples of the data, and the template for any function which processes a team), as per steps 1-3 of the design recipe. Give at least three examples of a team.
(5pts)
We'll say one team is “greater” than another if its offense is
higher than the other's defense, and its defense is higher than the other's offense.
Write the function
Familiarize yourself with the arcade game Breakout (a.k.a. “brick breaker”), such as this example. We will write a simplified version which does not need to deal with: score, powerups2, having more than one level, or number-of-lives.
There are three types of things (objects) which our program will need to model: bricks, balls, and paddles.
(10pts)
Give a data-definition for a ball in Java — that is, a
hints: General tips for deciding what fields an object needs:
Imagine a friend is playing your game, and paused+saved it mid-play. When they later re-open that save-file, what info needs to be in there about a particular ball, so the program can exactly re-construct the ball how it was the moment your friend saved it?
Do not include information that is not part of the object itself.
Do NOT include information which never changes (is “invariant”) for a class. For example, if all instances of an object are always the same color, you wouldn't have a field for the color. (You wouldn't want 1000 objects, each with their own field, which all necessarily hold the exact same value.)
Sometimes x,y coordinates suffice to describe something's position. However, sometimes more context might be needed. For example: what is the latitude and longitude of Virginia?
On a related note: For a problem below, you might be using
place-image , which places the center of an image at specified coordinates. If your internal representation is consonant with libraries you use, it can make things a smidgen easier.
Since this is Java, you will also need to create:
a constructor,
Note: You do not need to create getters/setters (and moreover, you should not). Moreover, for this homework and course, we will use immutable data, so you should not reassign to any fields3
enabling assertions in Java: When running your program, the JVM's default behavior is to entirely ignore assertions (!?!). You should run with4java --enableassertions someClassName , or convince your IDE to do this.
The remaining functions are to be in racket (not Java; the Java version is just to compare and emphasize how similar the immutable-Java and racket programs will be.
Note: Although full racket does support struct-inheritance, we will not use it here
hint:place-image is a handy function; it is similar tooverlay/xy except that it crops the result to the background.
hint: For test-cases, include drawing an brick that is: (a) in the middle of a small image; and (b) one that is mostly off the left-edge but has just a few pixels showing.
Note: Here's an image you can (modify to) use in your test-cases, in addition to a solid rectangle or whatever else you might choose: house-with-flowers.rkt. If you place this file in the same directory as other functions, you can just(require "house-with-flowers.rkt") , and then use its exported id (house-with-flowers , coincidentally). You don't need to print this file, but do submit it on D2L so that I can run your program.
This page licensed CC-BY 4.0 Ian Barland Page last generated | Please mail any suggestions (incl. typos, broken links) to ibarland ![]() |