Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Complete the random numbers using Math.random() in the correct ranges to choose x, y coordinates and random color in the range of 0-255 for the

Complete the random numbers using Math.random() in the correct ranges to choose x, y coordinates and random color in the range of 0-255 for the turtle. Put on some music and watch your turtle dance!

import java.util.*;

import java.awt.*;


 

public class DancingTurtles

{

  public static void main(String[] args)

  {


 

      World world = new World(500,400);

      Turtle yertle = new Turtle(world);


 

      // This is a loop that runs 10 times (you will learn to write loops in Unit 4)

      for(int i=1; i <= 10; i++)

      {

       // Can you choose a randomX between 0-500?

       // Can you adjust for the 20 pixel width of the turtle,

       // so it doesn't get cut off at the edges?

       // Move the range from 20 to 480.

       int randomX =

       // Can you choose a randomY between 0-400?

       // Can you adjust for the 20 pixel height of the turtle,

       // so it doesn't get cut off at the edges?

       int randomY =


 

       yertle.moveTo(randomX, randomY);

       yertle.turnRight();


 

       // Can you choose a random red, green, and blue value between 0-255?

       int randomR =

       int randomG =

       int randomB =


 

       yertle.setColor(new Color(randomR, randomG, randomB));


 

      } // end of loop

      world.show(true);

  }

}


 

Step by Step Solution

3.44 Rating (154 Votes )

There are 3 Steps involved in it

Step: 1

import javaawt import javautil public class Danci... 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

Introduction to Electrodynamics

Authors: David J. Griffiths

3rd Edition

978-0138053260, 013805326X, 8120316010, 978-8120316010

More Books

Students also viewed these Programming questions

Question

* What is the importance of soil testing in civil engineering?

Answered: 1 week ago

Question

Explain the concept of shear force and bending moment in beams.

Answered: 1 week ago