Use visual program to observe abstract classes and concrete subclasses.
"Ape" the code to create a third racer type.
Add an action to the abstract class, then implement in the concrete subclasses.
Watch it
Tortoise and Hare demo for PC/MAC
Tortoise and Hare demo for mobile devices
Instructions Part 1
Get the four files provided in the Solution section of this lab. Download them into an IDE project. Do not alter classes Racer, Tortoise, or Hare at this point.
Race.java modifications
Fill in the three places in Race.java (the driver program) where code is required. Find these sections by comments starting with "***** Student write"
Add switch statement to prepareToRace().
Add for loop to paintComponent() if clause (enhanced for-loop is best).
Add for loop to paintComponent() else clause (enhanced for-loop is best)
Save it, compile it, and run Race to watch the races! Run it with a variety of racers.
Instructions Part 2
Make a new Racer--anything you want.
The easiest way to do this is to make a new class and copy the code from either Tortoise.java or Hare.java.
Then modify the appearance (draw) and position (move) according to what fits your new racer.
Add your racer to the switch statement in Race.java so you can race it!
Add a new abstract method morph() to the abstract class Racer.java.
Implement some type of morphing to be enacted if the racer wins (or some other time if you prefer).
Some suggestions from students: dance, jump up and down, put on a hat, turn a different color, grow, shrink.