Assignment #5 CSI205 Assigned: 11/3/11
Due: 11/11/11
Assignment:
Create a class named HareAndTurtle that inherits from the Turtle class from assignment #4. The HareAndTurtle class adds a Hare (rabbit) to the original Turtle class that moves on it’s own 20 x 20 grid at the same time the Turtle moves on it’s 20 x 20 grid. The HareAndTurtle class is responsible for moving the Hare on it’s 20 x 20 grid and relies on Turtles methods to move the Turtle simultaneously on it’s 20 x 20 grid with one exception: the Turtle moves at ½ the distance as the Hare. For example, when the Hare moves 6 elements in the current direction, the Turtle moves 3 elements. When the Hare moves 5 elements, the Turtle moves 2. The Hare resembles the Turtle in all other respects: penUp(), turnLeft(), etc.
The HareAndTurtle class will have the same private instance variables as the Turtle class and implement the following methods:
- HareAndTurtle() – creates the Hare and the Turtle grids and initializes the grid, direction, and pen state for both the Hare and Turtle
- penUp() – places the pen in the “up” state for both the Turtle and the Hare
- penDown() – places the pen in the “down” state for both the Turtle and the Hare
- turnLeft() – turns both the Turtle and the Hare 90 degrees counter clockwise
- turnRight() - turns both the Turtle and the Hare 90 degrees clockwise
- move(howfar) – moves both the Hare howfar elements and the Turtle ½ howfar elements in the current direction
- printGrid() – prints the Turtle grid followed by the Hare grid.
You should modify the client program named TestTurtle.java in the class folder to test your implementation of the HareAndTurtle class to verify that your methods work correctly.
/home2/classes/csi205/TestTurtle.java
You should also obtain a working copy of the Turtle.class file from the class folder to test your implementation of HareAndTurtle
/home2/classes/csi205/Turtle.class
Notes:
-Format your code neatly. Comment your variables and include your name and student ID. Each method should contain comments describing its operation.
-You must use Turtle.class in the class folder to as the super class. This is a correctly coded copy of the Turtle class
-You must modify TestTurtle.java to ensure your new class is implemented correctly
-submit your assignment using the following command:
turnin-csi205 –c ci205 –p prog2 HareAndTurtle.java