Tue Oct 1 and Thu Oct 3
Due: Mon Oct 7 before 11:59PM
The purpose of this lab is to implement a simple class mutable class. This lab also introduces the concept of recursion and uses your implemented class in a recursive method to draw a version of the Heighway dragon curve.
You will need to implement the following features in your class:
toString
methodTurtle graphics is a method for drawing geometric primitives (such as points, lines, and curves) in the Cartesian (xy) plane. Logo was one of the early computer languages designed for educational purposes, and it had turtle graphics as one of its main features.
In turtle graphics, the client has control of a cursor (the turtle) that responds to commands such as "move forward 1.5 units", "turn right", and "turn left". As the turtle moves, it leaves behind a trail using a pen.
The turtle needs fields to represent its position in the plane,
the direction that it is facing, and the pen color. The position can be represented
using an IPoint2D
object, and the direction can be represented as an
angle between 0 and 360 degrees (measured counterclockwise from
the positive x axis). The pen color is represented using a
java.awt.Color
object. A subtle, but important feature of
this implementation is that all of the fields of the turtle are either
primitive type or immutable reference types.
Implement a Turtle
class that supports turtle graphics.
You should assume that the turtle can only face in the directions
left (180 degrees), up (90 degrees), right (0 degrees), and down
(270 degrees).
Also, you should assume that the turtle moves in the plane inside the rectangle
with the bottom left corner located at coordinates (-10, -8) and the
top right corner at coordinates (10, 8):
In eclipse:
lab3
)cse1030.drawing
Project
menuProperties
Java Build Path
Libraries
tabAdd External JARs...
buttoncse1030.drawing.IPoint2D
and cse1030.drawing.SimpleDrawing2
. The API for these classes
are here:
Turtle
so that it implements the following
API:
This means that you must create and complete the following fields, constructors, and methods:
Turtle()
Turtle(IPoint2D position, Color penColor)
Turtle(Turtle other)
move(double distance)
turnLeft()
turnRight()
getPosition
getAngle
getPenColor
setPenColor
toString()
You can test your implementation using the program found at the following link:
Test your program using the client program found at the last link shown above. Submit your program when you are finished:
submit 1030 L3 Turtle.java
package cse1030.drawing; import java.awt.Color; /** * A class that supports turtle graphics. The turtle is limited to moving in * only four directions: left, right, up, and down. The turtle is also limited * to moving in the rectangle with bottom left corner located at coordinates * (-10, -8) and the top left corner located at coordinates (10, 8). * * @author CSE1030_F_13_14 * */ public class Turtle { private IPoint2D position; private int angle; private Color penColor; private static final double X_MIN = -10; private static final double X_MAX = 10; private static final double Y_MIN = -8; private static final double Y_MAX = 8; }