Advertisement
Guest User

Untitled

a guest
Mar 18th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. package lesson16;
  2. import java.awt.Color;
  3. import java.util.*;
  4. import unit4.turtleLib.Turtle;
  5. public class UseTurtle6
  6. {
  7. static Turtle t1 = new Turtle();
  8. static Random rnd = new Random();
  9. static Scanner in = new Scanner(System.in);
  10. public static void main(String[] args)
  11. {
  12. int num, amount=10,longest=0,shortest=0,sum=0,avg=0,count=0,forward=0;
  13. t1.turnLeft(90);
  14. t1.moveForward(150);
  15. t1.turnRight(180);
  16. t1.tailDown();
  17. t1.moveForward(240);
  18. t1.tailUp();
  19. for(int i = 0; i<amount;i++)
  20. {
  21. num=rnd.nextInt((100-50)+1)+50;
  22. sum+=num;
  23. if(i==0)
  24. {
  25. longest = num;
  26. shortest = num;
  27. }
  28. if(num>longest)
  29. {
  30. longest = num;
  31. }
  32. if(num<shortest)
  33. {
  34. shortest=num;
  35. }
  36. }
  37. avg=sum/amount;
  38. t1.turnRight(180);
  39. for(int i = 0; i<3;i++)
  40. {
  41. if(count==0) // longest
  42. {
  43. t1.setTailColor(Color.blue);
  44. forward=80;
  45. }
  46. else if(count==1) // average
  47. {
  48. t1.setTailColor(Color.red);
  49. forward=60;
  50. }
  51. else if(count==2) // shortest
  52. {
  53. t1.setTailColor(Color.green);
  54. forward=40;
  55. }
  56. t1.moveForward(60);
  57. t1.turnRight(90);
  58. t1.tailDown();
  59. t1.moveForward(forward);
  60. t1.tailUp();
  61. t1.turnRight(180);
  62. t1.moveForward(forward);
  63. t1.turnRight(90);
  64. forward=0;
  65. count++;
  66. }
  67. System.out.println("The shortest is: "+shortest+", and his color is green.");
  68. System.out.println("The longest is: "+longest+", and his color is blue.");
  69. System.out.println("The average is: "+avg+", and his color is red.");
  70.  
  71. }
  72.  
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement