CSE1030 Lab 03

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:

Question 1: Implement a turtle class

Turtle 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:

  1. Create a new Java Project (perhaps called lab3)
  2. In your project, create a new Package called cse1030.drawing
  3. Download this jar file and add it to your project:
    1. select the Project menu
    2. select Properties
    3. on the left side of the dialog that appears, select Java Build Path
    4. on the right, select the Libraries tab
    5. click the Add External JARs... button
    6. add the jar file you downloaded
    This jar file contains the classes cse1030.drawing.IPoint2D and cse1030.drawing.SimpleDrawing2. The API for these classes are here:
  4. Complete the class Turtle so that it implements the following API: This means that you must create and complete the following fields, constructors, and methods:
    • a field for the position
    • a field for the angle
    • a field for the pen color
    • Turtle()
    • Turtle(IPoint2D position, Color penColor)
    • Turtle(Turtle other)
    • move(double distance)
    • turnLeft()
    • turnRight()
    • getPosition
    • getAngle
    • getPenColor
    • setPenColor
    • toString()
    Start with the code shown at the end of this lab.

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

Turtle starting code

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;