Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lesson16;
- import java.awt.Color;
- import java.util.*;
- import unit4.turtleLib.Turtle;
- public class UseTurtle6
- {
- static Turtle t1 = new Turtle();
- static Random rnd = new Random();
- static Scanner in = new Scanner(System.in);
- public static void main(String[] args)
- {
- int num, amount=10,longest=0,shortest=0,sum=0,avg=0,count=0,forward=0;
- t1.turnLeft(90);
- t1.moveForward(150);
- t1.turnRight(180);
- t1.tailDown();
- t1.moveForward(240);
- t1.tailUp();
- for(int i = 0; i<amount;i++)
- {
- num=rnd.nextInt((100-50)+1)+50;
- sum+=num;
- if(i==0)
- {
- longest = num;
- shortest = num;
- }
- if(num>longest)
- {
- longest = num;
- }
- if(num<shortest)
- {
- shortest=num;
- }
- }
- avg=sum/amount;
- t1.turnRight(180);
- for(int i = 0; i<3;i++)
- {
- if(count==0) // longest
- {
- t1.setTailColor(Color.blue);
- forward=80;
- }
- else if(count==1) // average
- {
- t1.setTailColor(Color.red);
- forward=60;
- }
- else if(count==2) // shortest
- {
- t1.setTailColor(Color.green);
- forward=40;
- }
- t1.moveForward(60);
- t1.turnRight(90);
- t1.tailDown();
- t1.moveForward(forward);
- t1.tailUp();
- t1.turnRight(180);
- t1.moveForward(forward);
- t1.turnRight(90);
- forward=0;
- count++;
- }
- System.out.println("The shortest is: "+shortest+", and his color is green.");
- System.out.println("The longest is: "+longest+", and his color is blue.");
- System.out.println("The average is: "+avg+", and his color is red.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement