Question
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...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started