Question: public class Turtle { private double x, y; // turtle is at (x, y) private double angle; // facing this many degrees counterclockwise from the

public class Turtle { private double x, y; // turtle is at (x, y) private double angle; // facing this many degrees counterclockwise from the x-axis // start at (x0, y0), facing a0 degrees counterclockwise from the x-axis public Turtle(double x0, double y0, double a0) { x = x0; y = y0; angle = a0; } // rotate orientation delta degrees counterclockwise public void turnLeft(double delta) { angle += delta; } // move forward the given amount, with the pen down public void goForward(double step) { double oldx = x; double oldy = y; x += step * Math.cos(Math.toRadians(angle)); y += step * Math.sin(Math.toRadians(angle)); StdDraw.line(oldx, oldy, x, y); } // copy to onscreen public void show() { StdDraw.show(); } // pause t milliseconds public void pause(int t) { StdDraw.pause(t); } public void setPenColor(Color color) { StdDraw.setPenColor(color); } public void setPenRadius(double radius) { StdDraw.setPenRadius(radius); } public void setCanvasSize(int width, int height) { StdDraw.setCanvasSize(width, height); } public void setXscale(double min, double max) { StdDraw.setXscale(min, max); } public void setYscale(double min, double max) { StdDraw.setYscale(min, max); } // sample client for testing public static void main(String[] args) { StdDraw.enableDoubleBuffering(); double x0 = 0.5; double y0 = 0.0; double a0 = 60.0; double step = Math.sqrt(3)/2; Turtle turtle = new Turtle(x0, y0, a0); turtle.goForward(step); turtle.turnLeft(120.0); turtle.goForward(step); turtle.turnLeft(120.0); turtle.goForward(step); turtle.turnLeft(120.0); } } 

Modify the Turtle class so that it has a "draw()" method and a "draw(Color color)" method. The implementation of these draw methods should draw a shape of your choosing. Create three subclasses of Turtle: SpiralTurtle, ConfusedTurtle, and SmartTurtle. Override the "draw()" methods of the subclasses. The SpiralTurtle "draw()" method should draw a spiral. The ConfusedTurtle "draw()" should draw an erratic pattern of random sized segments drawn in chaotic directions. The Deitel & Deitel textbook has a section entitled "Case Study: Random-Number Generation" which demonstrates how to generate random numeric values within a given range. Your ConfusedTurtle "draw" will need to randomly choose lengths and directions to control its drawing movement. Be sure that the "draw" method has a finite number of steps to its movement. The SmartTurtle "draw()" method should draw a "design" of your own choosing.

Create a BaleOfTurtles class. This class will have a "main" method. This method will perform the following operations:

Create a "World".

Initialize Array of three Turtles with references to a SpiralTurtle, a ConfusedTurtle, and a SmartTurtle. Be sure that these Turtles are placed with the current World.

Create a Color object representing a color of your choosing.

Iterate through your Turtle Array, and call the "draw(Color color)" using each Turtle reference within the Array.

Important!: Remove any duplicate code that you might have added.

One way of avoiding unnecessarily duplicated code (such as in a draw method), is to have one method call another method. In this manner, you can factor out the commonality. Also, please dont forget to place the new draw(Color...) method in the Turtle class as directed.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!