I already asked this question, but I am still having problems. I need this to co
ID: 3857734 • Letter: I
Question
I already asked this question, but I am still having problems. I need this to compile with the methods that are already written for the Introductions to Computing & Programming with JAVA a Multimedia Approach book by Mark Guzdial and Barbara Ericson. This was my previous question: I am working in the Introduction to Computing & Programming with JAVA A Multimedia Approach book by Mark Guzdial and Barbara Ericson. We are asked to 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. I am having trouble setting up the main class in Bale of Turtles. Can you help me do that with what they are asking. I also need help with the SprialTurtle drawing a spiral. Thanks
Explanation / Answer
BaleOfTurtles.java
import java.awt.Color;
public class BaleOfTurtles // extends Turtle // appears not to be needed
{
/*
// constructor:
public BaleOfTurtles()
{
}
*/
public static void main(String[] args)
{
World pond = new World();
Turtle turtle = new Turtle(pond);
turtle.draw();
Color specificColor = new Color(Color.RED);
turtle.draw(Color.red);
// need to do something with a turtle array
// Section 1: create local methods draw() & spiral()
turtle.setColor(Color.red);
turtle.setPenColor(Color.green);
turtle.spiral();
// Create 3 subclasses
SpiralTurtle newSpiral = new SpiralTurtle();
newSpiral.spiralDoStuff();
newSpiral.draw();
ConfusedTurtle newConfused = new ConfusedTurtle();
newConfused.confusedDoStuff();
newConfused.draw();
SmartTurtle newSmart =new SmartTurtle();
newSmart.smartDoStuff();
newSmart.draw();
}
}
SpiralTurtle.java
public class SpiralTurtle
//public class Turtle extends SimpleTurtle
{
// constructor
public SpiralTurtle()
{
}
public void spiralDoStuff()
{
System.out.println("SpiralTurtle.spiralDoStuff");
}
public void draw()
{
System.out.println("SpiralTurtle.draw()");
}
}
ConfusedTurtle.java
public class ConfusedTurtle
{
// constructor
public ConfusedTurtle()
{
}
public void confusedDoStuff()
{
System.out.println("ConfusedTurtle.confusedDoStuff");
}
public void draw()
{
System.out.println("ConfusedTurtle.draw()");
}
}
SmartTurtle.java
public class SmartTurtle
{
// constructor
public SmartTurtle()
{
}
public void smartDoStuff()
{
System.out.println("SmartTurtle.smartDoStuff");
}
public void draw()
{
System.out.println("SmartTurtle.draw()");
}
}
Turtle.java
import java.util.*;
import java.awt.*;
public class Turtle extends SimpleTurtle
{
////////////////// constructors ///////////////////////
/** Constructor that takes the x and y and a picture to
* draw on
* @param x the starting x position
* @param y the starting y position
* @param picture the picture to draw on
*/
public Turtle (int x, int y, Picture picture)
{
// let the parent constructor handle it
super(x,y,picture);
}
/** Constructor that takes the x and y and a model
* display to draw it on
* @param x the starting x position
* @param y the starting y position
* @param modelDisplayer the thing that displays the model
*/
public Turtle (int x, int y,
ModelDisplay modelDisplayer)
{
// let the parent constructor handle it
super(x,y,modelDisplayer);
}
/** Constructor that takes the model display
* @param modelDisplay the thing that displays the model
*/
public Turtle (ModelDisplay modelDisplay)
{
// let the parent constructor handle it
super(modelDisplay);
}
/**
* Constructor that takes a picture to draw on
* @param p the picture to draw on
*/
public Turtle (Picture p)
{
// let the parent constructor handle it
super(p);
}
/////////////////// methods ///////////////////////
public void draw()
{
this.forward(100);
this.turnRight();
this.forward(100);
this.turnRight();
this.forward(100);
this.turnRight();
this.forward(100);
this.turnLeft();
}
public void draw(Color color) // overloaded method, same method name different inputs
{
this.penUp();
this.moveTo(60, 80);
this.penDown();
this.setPenColor(color);
this.forward(200);
}
public void spiral()
{
// need to create body for this
int move = 100;
this.forward(move);
double corner = 1;
this.turn(corner);
this.forward(move);
this.turn(corner + corner);
}
public static void main(String[] args)
{
/*
World pond = new World();
Turtle turtle = new Turtle(pond);
System.out.println("New Turtle Assignment ");
*/
/*
// Section 1: create local methods draw() & spiral()
turtle.setColor(Color.red);
turtle.setPenColor(Color.green);
turtle.spiral();
*/
/*
// Create 3 subclasses
SpiralTurtle newSpiral = new SpiralTurtle();
newSpiral.spiralDoStuff();
newSpiral.draw();
ConfusedTurtle newConfused = new ConfusedTurtle();
newConfused.confusedDoStuff();
newConfused.draw();
SmartTurtle newSmart =new SmartTurtle();
newSmart.smartDoStuff();
newSmart.draw();
*/
/*
turtle.forward();
turtle.draw(); // task 1 complete
turtle.draw(Color.blue); // task 2 complete
*/
}
} // this }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.