Advertisement
StefiIOE

Untitled

Oct 19th, 2020
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.27 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.Arrays;
  3.  
  4. interface IMarathon {
  5. Athlete bestTime();
  6. int AthletesFrom(String s);
  7. }
  8.  
  9. class Athlete{
  10.  
  11. private String name;
  12. private String gender;
  13. private int age;
  14. private double time;
  15. private String country;
  16.  
  17. public String getName() {
  18. return this.name;
  19. }
  20.  
  21. public void setName(String name) {
  22. this.name = name;
  23. }
  24.  
  25. public String getGender() {
  26. return this.gender;
  27. }
  28.  
  29. public void setGender(String gender) {
  30. this.gender = gender;
  31. }
  32.  
  33. public int getAge() {
  34. return this.age;
  35. }
  36.  
  37. public void setAge(int age) {
  38. this.age = age;
  39. }
  40.  
  41. public double getTime() {
  42. return this.time;
  43. }
  44.  
  45. public void setTime(double time) {
  46. this.time = time;
  47. }
  48.  
  49. public String getCountry() {
  50. return this.country;
  51. }
  52.  
  53. public void setCountry(String country) {
  54. this.country = country;
  55. }
  56.  
  57.  
  58. public Athlete(String name, String gender, int age, double time, String country) {
  59. super();
  60. this.name = name;
  61. this.gender = gender;
  62. this.age = age;
  63. this.time = time;
  64. this.country = country;
  65. }
  66.  
  67.  
  68.  
  69.  
  70. @Override
  71. public String toString() {
  72. return name + "\n" + age + "\n" + country + "\n" + time +"\n";
  73. }
  74. }
  75.  
  76. class Marathon implements IMarathon {
  77. private String hostCountry;
  78. private int year;
  79. Athlete Athletes [] ;
  80.  
  81.  
  82. public String getHostCountry() {
  83. return this.hostCountry;
  84. }
  85.  
  86. public void setHostCountry(String hostCountry) {
  87. this.hostCountry = hostCountry;
  88. }
  89.  
  90. public int getYear() {
  91. return this.year;
  92. }
  93.  
  94. public void setYear(int year) {
  95. this.year = year;
  96. }
  97.  
  98. public Athlete [] getAthletes() {
  99. return this.Athletes;
  100. }
  101.  
  102. public void setAthletes(Athlete [] Athletes) {
  103. this.Athletes = Athletes;
  104. }
  105.  
  106.  
  107. public Marathon(String hostCountry, int year, Athlete [] Athletes) {
  108. super();
  109. this.hostCountry = hostCountry;
  110. this.year = year;
  111. this.Athletes = Athletes;
  112. }
  113.  
  114. @Override
  115. public String toString() {
  116. StringBuffer sb = new StringBuffer ();
  117. for(Athlete athlete : Athletes){
  118. sb.append(athlete.toString());
  119. }
  120. return hostCountry +"\n" + year + "\n" + sb.toString();
  121. }
  122.  
  123. @Override
  124. public Athlete bestTime (){
  125. double min = 999999;
  126. int minIndex = 0 ;
  127. for( int i = 0; i < Athletes.length ; i ++){
  128. if(Athletes[i].getTime() < min){
  129. min = Athletes[i].getTime();
  130. minIndex= i;
  131. }
  132. }
  133. return Athletes[minIndex];
  134. }
  135.  
  136. @Override
  137. public int AthletesFrom(String s){
  138. int count = 0;
  139. for(Athlete athlete : Athletes){
  140. if(athlete.getCountry().equals(s)){
  141. count++;
  142. }
  143. }
  144. return count;
  145. }
  146. }
  147.  
  148.  
  149. public class Test {
  150.  
  151. public static void main (String [] args) {
  152. Scanner input=new Scanner(System.in);
  153. int n=input.nextInt();
  154. Athlete[] atleticari = new Athlete[n];
  155.  
  156. String ime;
  157. String pol;
  158. int vozrast;
  159. double vreme;
  160. String zemja;
  161.  
  162. input.nextLine();
  163.  
  164. for(int i=0;i<n;i++)
  165. {
  166. ime = input.nextLine();
  167. pol = input.nextLine();
  168. vozrast = input.nextInt();
  169. vreme = input.nextDouble();
  170. input.nextLine();
  171. zemja = input.nextLine();
  172. atleticari[i]=new Athlete(ime,pol,vozrast,vreme,zemja);
  173. }
  174.  
  175. String mesto;
  176. int godina;
  177. String zemjaP;
  178. mesto = input.nextLine();
  179. godina = input.nextInt();
  180. input.nextLine();
  181.  
  182. Marathon m1 = new Marathon(mesto, godina, atleticari);
  183. System.out.print(m1.toString());
  184.  
  185. zemjaP = input.nextLine();
  186. System.out.println("Prvo mesto: " + m1.bestTime().toString());
  187. System.out.println("Ima vkupno " + m1.AthletesFrom(zemjaP) + " atleticar/i od " + zemjaP);
  188. }
  189. }
  190.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement