Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util. * ; import java.awt. * ; public class CustomTurtleRunner { public static void main ( String [ ] args ) { World world

import java.util.*;
import java.awt.*;
public class CustomTurtleRunner
{
public static void main(String[] args)
{
World world1= new World(400,400);
//1. Change the constructor call below to create a large
//150x200 CustomTurtle with a green body (Color.green)
// and a blue shell (Color.blue) at position (150,300).
// Move it forward to see it.
CustomTurtle turtle1= new CustomTurtle(world1,Color.green,Color.blue,150,300);
turtle1.forward();
//2. Create a small 25x50 CustomTurtle with a red body
// and a yellow shell at position (350,200)
// Move it forward to see it.
CustomTurtle turtle2= new CustomTurtle(350,200, world1, Color.red, Color.yellow,25,50);
turtle2.forward();
//3. Create a CustomTurtle of your own design
CustomTurtle turtle3= new CustomTurtle(150,150, world1, Color.red, Color.pink, 75,100);
turtle3.setPenWidth(3);
turtle3.turnRight();
turtle3.forward();
turtle3.turnLeft();
turtle3.forward();
turtle3.turnLeft();
turtle3.forward();
turtle3.turnLeft();
turtle3.forward();
turtle3.turnRight();
turtle3.forward();
turtle3.turnRight();
turtle3.forward();
turtle3.turnRight();
turtle3.forward();
turtle3.turnLeft();
turtle3.forward();
turtle3.turnLeft();
turtle3.forward();
turtle3.turnLeft();
turtle3.forward();
turtle3.turnRight();
turtle3.forward();
turtle3.turnRight();
turtle3.forward();
turtle3.turnRight();
turtle3.forward();
turtle3.turnLeft();
turtle3.forward();
turtle3.turnLeft();
turtle3.forward();
turtle3.turnLeft();
turtle3.forward();
world1.show(true);
}
}
class CustomTurtle extends Turtle
{
private int x;
private int y;
private World w;
private Color bodycolor;
private Color shellcolor;
private int width;
private int height;
/** Constructor that takes the model display
* @param modelDisplay the thing that displays the model or world
*/
public CustomTurtle(ModelDisplay modelDisplay)
{
// let the parent constructor handle it
super(modelDisplay);
}
/** Constructor that takes the model
* display to draw it on and custom colors and size
* @param m the world
* @param body : the body color
* @param shell : the shell color
* @param w: width
* @param h: height
*/
public CustomTurtle(ModelDisplay m, Color body, Color shell, int w, int h)
{
// let the parent constructor handle it
super(m);
bodycolor = body;
setBodyColor(body);
shellcolor = shell;
setShellColor(shell);
height = h;
width = w;
setHeight(h);
setWidth(w);
}
}
/** Constructor that takes the x and y and a model
* display to draw it on and custom colors and size
* @param x the starting x position
* @param y the starting y position
* @param m the world
* @param body : the body color
* @param shell : the shell color
* @param w: width
* @param h: he
*/

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 19 21 2012 Proceedings Part 3 Lnai 7198

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284922, 978-3642284922

More Books

Students also viewed these Databases questions