Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. import java.util.Random;
  2. import java.util.Date;
  3.  
  4. class CoordinateGenerator {
  5. private Random randomGenerator;
  6. public CoordinateGenerator()
  7. {
  8. Date now = new Date();
  9. long sec = now.getTime();
  10. randomGenerator = new Random(sec);
  11. }
  12. public int generateX()
  13. {
  14. int x = randomGenerator.nextInt(101);
  15. if(x < 5)
  16. {
  17. x = 0;
  18. }
  19. else if(x > 95)
  20. {
  21. x = 100;
  22. }
  23. else
  24. {
  25. x = randomGenerator.nextInt(99) + 1;
  26. }
  27. return x;
  28. }
  29. public int generateY()
  30. {
  31. int y = randomGenerator.nextInt(101);
  32. if(y < 5)
  33. {
  34. y = 0;
  35. }
  36. else if(y > 95)
  37. {
  38. y = 50;
  39. }
  40. else
  41. {
  42. y = randomGenerator.nextInt(49) + 1;
  43. }
  44. return y;
  45. }
  46. }
  47. class Out extends Exception
  48. {
  49. public Out()
  50. {
  51. super("Out!");
  52. }
  53. }
  54. class Gol extends Exception
  55. {
  56. public Gol()
  57. {
  58. super("Gol!");
  59. }
  60. }
  61. class Corner extends Exception
  62. {
  63. public Corner()
  64. {
  65. super("Corner!");
  66. }
  67. }
  68. class Minge
  69. {
  70. private int x, y;
  71. public Minge(int x, int y)
  72. {
  73. this.x=x;
  74. this.y=y;
  75. }
  76. public int detX()
  77. {
  78. return x;
  79. }
  80. public int detY()
  81. {
  82. return y;
  83. }
  84. public void suteaza() throws Out, Gol, Corner
  85. {
  86. CoordinateGenerator x_new = new CoordinateGenerator();
  87. CoordinateGenerator y_new = new CoordinateGenerator();
  88. x=x_new.generateX();
  89. y=y_new.generateY();
  90. if(y==0 || y==50)
  91. throw new Out();
  92. else if ((x==0||x==100)&&(y>=20&&y<=30))
  93. throw new Gol();
  94. else if ((x==0||x==100)&&((0<y)&&(y<20)||(30<y)&&(y<50)))
  95. throw new Corner();
  96. }
  97.  
  98. }
  99. class Joc
  100. {
  101. private int nr_goluri1, nr_goluri2;
  102. private int nr_out, nr_corner;
  103. private String echipa1, echipa2;
  104. public Joc(String e1, String e2)
  105. {
  106. this.echipa1 = e1;
  107. this.echipa2 = e2;
  108. }
  109. public String toString()
  110. {
  111. String s= " ";
  112. s = s+nr_goluri1+" "+echipa1+"-"+echipa2+" "+nr_goluri2+" ";
  113. s = s+"Numar outuri: "+nr_out+" Numar Cornere: "+nr_corner+" ";
  114. return s;
  115. }
  116. public void simuleaza()
  117. {
  118. Minge m= new Minge(50,25);
  119. int i;
  120. for(i=0;i<1000;i++)
  121. try{
  122. m.suteaza();
  123. }
  124. catch(Out e)
  125. {
  126. Minge m1 = new Minge (m.detX(), m.detY());
  127. }
  128. catch(Gol e)
  129. {
  130. Minge m1 = new Minge (50,25);
  131. }
  132. catch(Corner e)
  133. {
  134.  
  135. }
  136. }
  137. }
  138. class Main
  139. {
  140. public static void main (String argv[])
  141. {
  142. Joc m1= new Joc("UTA Arad", "Poli Timisoara");
  143. System.out.println(m1.toString());
  144. }
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement