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

homelecturesrecipeexamshwsD2Lbreeze (snow day; distance)

structs
structs
hw04b

Due:
Oct.0204 (Wed) 15:00, D2L and hardcopy.
Your submitted file should be named “hw04.rkt”, plus any .java files.
hw04a is a multiple-choice quiz on D2L

Standard instructions for all homeworks:


Familiarize yourself with the frogger arcade game. We will write a version of this game, but simplified in some ways:

You are welcome to add additional features, or modify details. (For instance, having trucks that travel in each direction, etc..) If you use images or sounds for your game, you must make sure you have the right to use them.


  1. We start by representing trucks, and writing a method involving them.
    1. Give a Java class to represent a truck (non-static fields and constructor only). Note that no images are involved (since the image doesn't vary from one truck to another1).
    2. Give some Java statements which create two different Truck objects.
    3. The static method move will which takes in a truck object, and returns a whole new truck object which has traveled for one unit of time (a "tick").
      1. Write a stub method.
      2. Write two test cases. Your tests can either (a) print the actual and expected Trucks (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 Truck.main.
      3. After writing the test cases and getting them to compile, now complete the method.
    You should have a Truck.java file (which compiles and runs); it should be less than a page2 of well-spaced, commented code.
  2. Repeat all parts of the previous question using scheme (racket) structs and functions, rather than Java classes and methods. (Use check-expect for your test cases, of course.)
  3. Now that we understand how to represent and process trucks, we'll do the similar thing for a prince(ss).

    Write a scheme (racket) struct for a prince(ss). Following the design recipe, write the function udpate-prince(ss) which returns a new prince(ss) one tick later (in the same location, but a little closer to disappearing.)

    Note that you don't have toshouldn't worry about what to do when the prince(ss)'s time has run out, if you don't want; other later code can check for whether a prince(ss) should disappear/teleport.

Hints:


1 In your future game, you may want to have trucks moving both left-to-right and right-to-left. Even there, the image being used depends on the truck's direction/speed, and is not an independent quantity. [If you wanted to have different trucks use entirely different icons, then that would require a field, but we'll decline doing that for now.]      
2If you added a boilerplate equals and hashCode, it'll be more than a page. And if you have use JUnit, that necessitates an additional file TruckTest.java.      

homelecturesrecipeexamshwsD2Lbreeze (snow day; distance)


©2017, Ian Barland, Radford University
Last modified 2017.Oct.04 (Wed)
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Rendered by Racket.