|
Due:
Oct.08 (Mon) 12:00, 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 qz03, 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.
(10pts)
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 Galaxians arcade game, such as this example. We will write a simplified version: it will have an enemy fleet that hovers back and forth, and occasionally enemies that dive down. Your ship can move left/right and up/down, and shoot. Our bare-bones program does not need to deal with: score, enemy shots, the enemy fleet slowly descending, diving enemies with "complicated" paths, multiple waves (levels), the player's un-fired missile being drawn on top of their ship, sound, different types of enemies, or number-of-lives.
Give a Java class to represent a missile (non-static fields and constructor only). Your representation should account for how some missiles may be traveling upward, and others downward. (We won't require implementing alien-missiles, but our data-definition should still allow it.) Note that no images are involved, since the image doesn't vary from one missile to another (at least not in our simple version).
Be sure to use good, self-documenting field-names (not necessarily long ones), and use comments to specify any units or other non-obvious interpretation.
Note that although there will be some fields in common among our three data types, we will not use struct-inheritance4 for this assignment — just repeat the duplicate fields in each new type/struct.
Hints:
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 missile, so the program can exactly re-construct the missile how it was the moment your friend saved it?
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 held the exact same value. Clearly redundant.)
This page licensed CC-BY 4.0 Ian Barland Page last generated | Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |