Mitrezzz

Маратон

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