RU beehive logo ITEC dept promo banner
ITEC 380
2018fall
ibarland

structs
hw04

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:

  1. (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.

  2. (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 team>? to implement this. Follow all the steps of the design recipe1. As always, be sure to think about enough test-cases to cover the interesting situations (5 of the pts). (In this case, six or seven should suffice, if they each cover a different situation.)


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.

  1. We start by representing missiles, and writing a method involving them.
    1. 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.

    2. Give some Java statements which create two different Missile objects.
    3. Write the method Missile#move() which and returns a whole new Missile object similar to this, but after having traveled for one “tick” (frame). Ignore any edge-of-screen issues.
      1. Write a stub method.
      2. Write two test cases. Your tests can either (a) print the actual and expected Missiles (you'll need a toString), or (b) use assert and override equals (or (c) use Junit). In any case, you may want to refer to the code we wrote in class, for Book.java. You can put those test cases in AlienMissile.main.
      3. After writing the test cases and getting them to compile, now complete the method.
    You should have a Missile.java file (which compiles and runs, even if it doesn't print anything); it should be less than a page2 of well-spaced, commented code. (Note that if you run a java program with assertions, you should run it as3 java --enableassertions className. Omitting this flag means all assertions are disabled, and won't even be run, oops!)
  2. Repeat all parts of the previous question using racket structs and functions, rather than Java classes and methods. (Use check-expect for your test cases, of course.)
  3. (6pts) What are two other types of things (objects) in the game, that our program will need to model? For each of them, follow steps 1-3 of the design recipe, using racket. (No functions for these types, yet.)

    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:


1 Note that the stub-function, step 5e, gets replaced with the real body (step 7), so it won't be visible in what you submit. Also, you don't need to include the names of constructors/selectors; that was part of quiz03 but not part of the design recipe.      
2 If you added a boilerplate equals and hashCode, it'll be more than a page. And if you have use JUnit instead of simple asserts, that necessitates an additional file AlienTest.java.      
3 The long flag --enableassertions can be abbreviated -ea.      
4 Struct-inheritance is in full racket, but is not in the teaching languages.      

logo for creative commons by-attribution license
This page licensed CC-BY 4.0 Ian Barland
Page last generated
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Rendered by Racket.