COMP 1672, Spring 2012
Assignment 4 - Part 1
Create a new type of Turtle called a StackTurtle by creating a StackTurtle
class. The StackTurtle class should extend the Turtle class.
Each StackTurtle maintains a Stack of geometric point locations (each location is a x-coordinate and y-coordinate pair).
In addition to appropriate instance variables and constructors, the StackTurtle class should contain the following methods:
- public Point pop() -- Remove and then return the top Point on the StackTurtle's Stack of Point objects.
- public void push( Point aPoint ) -- adds aPoint to the top of the StackTurtle's Stack of Point objects.
- public int stackSize() -- the number of Points on the StackTurtle's Stack of Point objects.
Now create a command method for StackTurtle (similar to the one in Turtle) with the following additions:
- Whenever a [ character is seen in the command string, the
StackTurtle should push its current position onto its Stack of Points.
- Whenever a ] character is seen in the command string, the
StackTurtle should pop the top element from its Stack of Points and then
change its current location to that point.
Write a main method to test the StackTurtle class.