Advertisement
BorjanCrvenkov

Aips lab1 Maraton

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