Question

On the Turtle class I need to make a method so turtle 0 and turtle 2...

On the Turtle class I need to make a method so turtle 0 and turtle 2 to "kiss" or touch their heads. Everything that can be use is in the SimpleTurtle link. https://www2.cs.uic.edu/~i101/doc/SimpleTurtle.html

public void turtleTricks()
{
int worldWidth = 800;
int worldHeight = 600;
Random random = new Random();
World earth = new World(worldWidth, worldHeight );//Make a big world for turtles.
  
Turtle[] turtles = new Turtle[5];
int xLocation, yLocation, angle;
for ( int i = 0; i < turtles.length; i++ )
{
xLocation = random.nextInt( worldWidth - 100 );
yLocation = random.nextInt( worldHeight - 100 );
angle = random.nextInt( 360 );
turtles[i] = new Turtle( earth );
turtles[i].penUp(); //pick up the pen just to put each into a different location
turtles[i].moveTo(xLocation + 50, yLocation + 50 );
//subtracted 100 from each dimension, then add 50 to make sure no turtle is placed too
//close to an edge.
turtles[i].turn( angle ); //Have them all start facing different directions.
turtles[i].penDown(); //Ready to draw.
}
  
  
  
//testing starts here
//turtles[0].drawSquare();
//turtles[1].drawSquare( 200 );
//turtles[2].drawRectangle( 50, 200 );
//turtles[3].drawRegularPolygon( 8, 100 );
//turtles[4].drawRegularPolygon( 5, 100 );


turtles[0].kiss( turtles[2]);
  
}//end turtleTricks

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 kiss( int turtles[] )
{

}
  


} // end of class Turtle, put all new methods before this


0 0
Add a comment Improve this question Transcribed image text
Answer #1

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 kiss( Turtle turtles[] )
{
// first calculate distance between them
int x1 = turtles[1].x - turtles[0].x;
// first turn turtle to facing each other
turtles[0].turnToFace(turtles[1].x, turtles[1].y);
// moving forward two turtles
turtles[0].forward(x1/2);
turtles[1].forward(x/2);
}

} // end of class Turtle, put all new methods before this

Add a comment
Know the answer?
Add Answer to:
On the Turtle class I need to make a method so turtle 0 and turtle 2...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need help with this code, I have it started here import sys import turtle menu...

    I need help with this code, I have it started here import sys import turtle menu = "Press 1 for Flower" UserChoice = input(menu) #function to draw squares def draw_square(square): for i in range(0,2): square.forward(100) square.right(70) square.forward(100) square.right(110) #function to draw flower def draw_flower(petalNumber): window = turtle.Screen() window.bgcolor("yellow") pen = turtle.Turtle() pen.shape("triangle") pen.color("red")    for number in range(0,petalNumber): draw_square(pen) pen.right(360/petalNumber) for i in range(0,4): pen.circle(20) pen.right(90)    pen.right(90) pen.forward(300) pen.right(90) draw_square(pen) pen.left(180) draw_square(pen) pen.left(270) pen.forward(200) window.exitonclick() #function for original art...

  • (JAVA NetBeans) Write programs in java Example 10.21-24 //Animal.java /** Animal class * Anderson. Franceschi */...

    (JAVA NetBeans) Write programs in java Example 10.21-24 //Animal.java /** Animal class * Anderson. Franceschi */ import java.awt.Graphics; public abstract class Animal { private int x; // x position private int y; // y position private String ID; // animal ID /** default constructor * Sets ID to empty String */ public Animal( ) { ID = ""; } /** Constructor * @param rID Animal ID * @param rX x position * @param rY y position */ public Animal( String...

  • a derived class from Organism. You must complete the constructors, and the method definitions that were...

    a derived class from Organism. You must complete the constructors, and the method definitions that were abstract methods in Organism. /** Organism.java * Definition for the Organism base class. * Each organism has a reference back to the World object so it can move * itself about in the world. */ public abstract class Organism {    protected int x, y;       // Position in the world    protected boolean moved;   // boolean to indicate if moved this turn   ...

  • Java Programming: Math Quiz

    Starting codes:MathQuiz.javaimport java.util.Scanner;public class MathQuiz {    private final int NUMBER_OF_QUESTIONS = 10;    private final MathQuestion[] questions = new MathQuestion[NUMBER_OF_QUESTIONS];    private final int[] userAnswers = new int[NUMBER_OF_QUESTIONS];    public static void main(String[] args) {        MathQuiz app = new MathQuiz();        System.out.println(app.welcomeAndInstructions());        app.createQuiz();        app.administerQuiz();        app.gradeQuiz();    }    private String welcomeAndInstructions() {        return "Welcome to Math Quiz!\n" +         ...

  • This week we want to build an inheritance hierarchy using targets. You now need to take...

    This week we want to build an inheritance hierarchy using targets. You now need to take the Target class we have built and create a subclass that inherits from it. You can do whatever you want here, but it should be obvious how you changed the target. Some examples might include adding an additional ellipse to the target to increase the number of levels or changing up the colors. Once you have come up with one way to change the...

  • Create a basic math quiz program that creates a set of 10 randomly generated math questions for the following operations:

    Create a basic math quiz program that creates a set of 10 randomly generated math questions for the following operations:AdditionSubtractionMultiplicationDivisionModuloExponentThe following source files are already complete and CANNOT be changed:MathQuiz.java (contains the main() method)OperationType.java (defines an enumeration for valid math operations and related functionality)The following source files are incomplete and need to be coded to meet the indicated requirements:MathQuestionable.javaA Random object called RANDOM has already been declared and assigned, and you must not change this assignment in any way.Declare and assign an interface integer called MAX_SMALL and assign it the...

  • Create a basic math quiz program that creates a set of 10 randomly generated math questions for the following operations:

    Create a basic math quiz program that creates a set of 10 randomly generated math questions for the following operations:AdditionSubtractionMultiplicationDivisionModuloExponentThe following source files are already complete and CANNOT be changed:MathQuiz.java (contains the main() method)OperationType.java (defines an enumeration for valid math operations and related functionality)The following source files are incomplete and need to be coded to meet the indicated requirements:MathQuestionable.javaA Random object called RANDOM has already been declared and assigned, and you must not change this assignment in any way.Declare and assign an interface integer called MAX_SMALL and assign it the...

  • Adv. Java program - create a math quiz

    Create a basic math quiz program that creates a set of 10 randomly generated math questions for the following operations:AdditionSubtractionMultiplicationDivisionModuloExponentThe following source files are already complete and CANNOT be changed:MathQuiz.java (contains the main() method)OperationType.java (defines an enumeration for valid math operations and related functionality)The following source files are incomplete and need to be coded to meet the indicated requirements:MathQuestionable.javaA Random object called RANDOM has already been declared and assigned, and you must not change this assignment in any way.Declare and assign an interface integer called MAX_SMALL and assign it the...

  • This is my code that i need to finish. In BoxRegion.java I have no idea how...

    This is my code that i need to finish. In BoxRegion.java I have no idea how to create the constructor. I tried to use super(x,y) but It is hard to apply. And Also In BoxRegionHashTable, I don't know how to create displayAnnotation BoxRegion.java ------------------------------------------------ public final class BoxRegion { final Point2D p1; final Point2D p2; /** * Create a new 3D point with given x, y and z values * * @param x1, y1 are the x,y coordinates for point...

  • I need help with the following Java code Consider a class Fraction of fractions. Each fraction...

    I need help with the following Java code Consider a class Fraction of fractions. Each fraction is signed and has a numerator and a denominator that are integers. Your class should be able to add, subtract, multiply, and divide two fractions. These methods should have a fraction as a parameter and should return the result of the operation as a fraction. The class should also be able to find the reciprocal of a fraction, compare two fractions, decide whether two...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT