For this homework, you will need to use the ProfessorJ Intermediate language. (You will not be using the public/private access modifiers for this assignment. You will be using abstract classes.)
Examples class that contains all
your tests.
draw() for all classes defined in Problem 1.
onTick() for all classes defined in Problem 1.
makeStar() that
produces a new Star at a random horizontal position at the top of the
Canvas, with some randomly-chosen lifespan.
The following code will generate a random number in the range 0 to 4:
// produce a random number in the range 0 to 4
int randomNum(){
return new Random().nextInt() % 5;
}
Modify this method as needed to generate a number in the desired range. You
must also
add the following import statement to the other import statements at the
beginning of your program:
import java.util.Random;The introduction of random numbers makes testing trickier. For now, you can construct tests that check that each field of the newly-created Star satisfies some set of conditions.
foundStar() in the classes that represent a
list of Stars. foundStar() consumes a UFO and determines
whether or not there is a Star in the list that is close enough to the UFO to
be caught. You may use the built-in method Math.abs() or
Math.sqrt() to determine when a star and the given ufo are close enough.
caughtStar() in the classes that represent
a list of Stars. caughtStar() consumes a UFO and produces a Star
that the UFO can catch. This method must not be activated unless you have
already verified that there is a Star in the list that is close enough to
be caught. If there are two or more such Stars, the method should produce the
first one it finds.
You will need to implement this method in your empty list of Stars class, even though the method will never be activated on an empty list of Stars. Use Util.error to terminate the program if caughtStar() is activated on an empty list.
catchStar() in the UFO class. It consumes
a Star and produces a UFO with its fuel supply increased by the Star's
lifespan.
replace() in the classes that represent
a list of Stars. replace() consumes a Star and replaces that
Star in the list with a new Star produced by the makeStar()
method. (Hint: the equals() method in Java's Object class
will be useful here.)
Again, this is a difficult method to test because of its reliance on the random numbers generated by makeStar(). In a comment in your Examples class, explain how you convinced yourself that your replace() method was correct.
onKeyEvent() in the UFO class. The
method consumes a String that represents the arrow key pressed by the
player of the game and produces a UFO at a new location.
return true.
draw() in the class that represents
your game world.
onKeyEvent() in the class that represents
your game world. The method should consume a String, and return a
new game world based on the player's input.
onTick() in the class that
represents your game world. It
needs to check to see if the UFO has run out of fuel, or if the UFO has
caught a Star. If a Star has been caught, it should be replaced. If neither
of these conditions is true, the method just lets the clock tick.
Have you tested everything? If so, then go ahead and try playing the game.
Define a method called go() in your game world class, and activate
it from the Examples class, as shown in the Exploding Sun example. Have fun!
Using web-based turnin, turn in a single file containing all code and documentation for this assignment. Follow the naming conventions when naming your file. Both partners' names and wpi login names should appear in a comment at the top of the file.