Advertisement
JStefan

APS_Vezbi_Maraton

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