Advertisement
Guest User

Maraton

a guest
Oct 19th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.51 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.Scanner;
  3.  
  4. interface IMaraton{
  5. Atleticar najdobroVreme();
  6. int atleticariOd(String s);
  7. }
  8.  
  9. class Atleticar
  10. {
  11. private String ime;
  12. private String pol;
  13. private int vozrast;
  14. private double vreme;
  15. private String zemja;
  16.  
  17. public Atleticar()
  18. {
  19. super();
  20. }
  21.  
  22. public Atleticar (String ime, String pol, int vozrast, double vreme, String zemja)
  23. {
  24. super();
  25. this.ime=ime;
  26. this.pol=pol;
  27. this.vozrast=vozrast;
  28. this.vreme=vreme;
  29. this.zemja=zemja;
  30. }
  31. public String getIme()
  32. {
  33. return ime;
  34. }
  35. public String getPol()
  36. {
  37. return pol;
  38. }
  39. public int getVozrast()
  40. {
  41. return vozrast;
  42. }
  43. public double getVreme()
  44. {
  45. return vreme;
  46. }
  47. public String getZemja()
  48. {
  49. return zemja;
  50. }
  51.  
  52. public void setIme(String ime)
  53. {
  54. this.ime=ime;
  55. }
  56. public void setPol(String pol)
  57. {
  58. this.pol=pol;
  59. }
  60. public void setVozrast(int vozrast)
  61. {
  62. this.vozrast=vozrast;
  63. }
  64. public void setVreme(double vreme)
  65. {
  66. this.vreme=vreme;
  67. }
  68. public void getZemja(String zemja)
  69. {
  70. this.zemja=zemja;
  71. }
  72.  
  73. @Override
  74. public String toString()
  75. {
  76. return ime + "\n" + vozrast + "\n" + zemja + "\n" + vreme + "\n";
  77. }
  78.  
  79. }
  80.  
  81. class Maraton implements IMaraton
  82. {
  83. private String mestoNaOdrzuvanje;
  84. private int godina;
  85. private Atleticar[] atleticari;
  86.  
  87. public Maraton()
  88. {
  89. super();
  90. }
  91. public Maraton(String mestoNaOdrzuvanje, int godina, Atleticar[] atleticari)
  92. {
  93. super();
  94. this.mestoNaOdrzuvanje=mestoNaOdrzuvanje;
  95. this.godina=godina;
  96. this.atleticari=atleticari;
  97. }
  98.  
  99. public String getMestoNaOdrzuvanje()
  100. {
  101. return mestoNaOdrzuvanje;
  102. }
  103. public void setMestoNaOdrzuvanje(String mestoNaOdrzuvanje)
  104. {
  105. this.mestoNaOdrzuvanje=mestoNaOdrzuvanje;
  106. }
  107. public int getGodina()
  108. {
  109. return godina;
  110. }
  111. public void setGodina(int godina)
  112. {
  113. this.godina=godina;
  114. }
  115. public Atleticar[] getAtleticari()
  116. {
  117. return atleticari;
  118. }
  119. public void setAtleticari(Atleticar[] atleticari)
  120. {
  121. this.atleticari=atleticari;
  122. }
  123.  
  124. @Override
  125. public String toString() {
  126. return mestoNaOdrzuvanje + "\n" + godina + "\n"
  127. + Arrays.toString(atleticari).replace("[", "").replace("]", "").replace(", ","").trim()+"\n";
  128. }
  129.  
  130. public Atleticar najdobroVreme()
  131. {
  132. double najdobro = atleticari[0].getVreme();
  133. int index=0;
  134. for (int i=1; i<atleticari.length;i++)
  135. {
  136. if(atleticari[i].getVreme()<najdobro)
  137. {
  138. najdobro=atleticari[i].getVreme();
  139. index=i;
  140. }
  141. }
  142. return atleticari[index];
  143. }
  144.  
  145. public int atleticariOd(String s)
  146. {
  147. int brojac=0;
  148. for (int i=0;i<atleticari.length;i++)
  149. {
  150. if(atleticari[i].getZemja().equals(s))
  151. brojac++;
  152. }
  153. return brojac;
  154. }
  155. }
  156.  
  157. public class ZadacaMaraton {
  158.  
  159. public static void main(String[] args) {
  160. Scanner input=new Scanner(System.in);
  161. int n=input.nextInt();
  162. Atleticar[] atleticari = new Atleticar[n];
  163.  
  164. String ime;
  165. String pol;
  166. int vozrast;
  167. double vreme;
  168. String zemja;
  169.  
  170. input.nextLine();
  171.  
  172. for(int i=0;i<n;i++)
  173. {
  174. ime = input.nextLine();
  175. pol = input.nextLine();
  176. vozrast = input.nextInt();
  177. vreme = input.nextDouble();
  178. input.nextLine();
  179. zemja = input.nextLine();
  180. atleticari[i]=new Atleticar(ime,pol,vozrast,vreme,zemja);
  181. }
  182.  
  183. String mesto;
  184. int godina;
  185. String zemjaP;
  186. mesto = input.nextLine();
  187. godina = input.nextInt();
  188. input.nextLine();
  189.  
  190. Maraton m1 = new Maraton(mesto, godina, atleticari);
  191. System.out.print(m1.toString());
  192.  
  193. zemjaP = input.nextLine();
  194. System.out.println("Prvo mesto: " + m1.najdobroVreme().toString());
  195. System.out.println("Ima vkupno " + m1.atleticariOd(zemjaP) + " atleticar/i od " + zemjaP);
  196. }
  197. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement