Advertisement
NenadKocev

[Java] Маратон

Oct 20th, 2017
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.13 KB | None | 0 0
  1. import java.util.Scanner;
  2. interface IMaraton {
  3.     public Atleticar najdobroVreme();
  4.     public int atleticariOd(String s);
  5. }
  6.  
  7. class Atleticar{
  8.     private String ime;
  9.     private String pol;
  10.     private int vozrast;
  11.     private double vreme;
  12.     private String poteklo;
  13.     Atleticar(){}
  14.     Atleticar(String ime, String pol, int vozrast, double vreme, String poteklo){
  15.         this.ime = ime;
  16.         this.pol = pol;
  17.         this.vozrast = vozrast;
  18.         this.vreme = vreme;
  19.         this.poteklo = poteklo;
  20.     }
  21.     /*toString() - формат: име / возраст / земја на потекло / време на истрчување (сите параметри одделени со празно место)*/
  22.     @Override
  23.     public String toString(){
  24.         return ime + "\n" + vozrast + "\n" + poteklo + "\n" + vreme + "\n";
  25.     }
  26.     double getVreme(){return vreme;}
  27.     String getPoteklo(){return poteklo;}
  28. }
  29.  
  30. class Maraton implements IMaraton{
  31.     private String mesto;
  32.     private int godina;
  33.     private Atleticar [] atleticari;
  34.     Maraton(){}
  35.     Maraton(String mesto, int godina, Atleticar [] atleticari){
  36.         this.mesto = mesto;
  37.         this.godina = godina;
  38.         this.atleticari = atleticari;
  39.     }
  40.     @Override
  41.     public String toString(){
  42.         StringBuilder rez = new StringBuilder(mesto + "\n" + godina + "\n");
  43.         for(Atleticar m : atleticari)
  44.             rez.append(m.toString());
  45.         return(rez.toString());
  46.     }
  47.  
  48.     @Override
  49.     public Atleticar najdobroVreme() {
  50.         Atleticar najdobar = atleticari[0];
  51.         for(Atleticar x : atleticari){
  52.             if(x.getVreme() < najdobar.getVreme())
  53.                 najdobar = x;
  54.         }
  55.         return najdobar;
  56.     }
  57.  
  58.     @Override
  59.     public int atleticariOd(String s) {
  60.         int od = 0;
  61.         for(Atleticar x : atleticari){
  62.             if(x.getPoteklo().equals(s))
  63.                 od++;
  64.         }
  65.         return od;
  66.     }
  67. }
  68.  
  69. public class ZadacaMaraton {
  70.  
  71.     public static void main(String[] args) {
  72.         Scanner input=new Scanner(System.in);
  73.         int n=input.nextInt();
  74.         Atleticar[] atleticari = new Atleticar[n];
  75.  
  76.         String ime;
  77.         String pol;
  78.         int vozrast;
  79.         double vreme;
  80.         String zemja;
  81.  
  82.         input.nextLine();
  83.  
  84.         for(int i=0;i<n;i++)
  85.         {
  86.             ime = input.nextLine();
  87.             pol = input.nextLine();
  88.             vozrast = input.nextInt();
  89.             vreme = input.nextDouble();
  90.             input.nextLine();
  91.             zemja = input.nextLine();
  92.             atleticari[i]=new Atleticar(ime,pol,vozrast,vreme,zemja);
  93.         }
  94.  
  95.         String mesto;
  96.         int godina;
  97.         String zemjaP;
  98.         mesto = input.nextLine();
  99.         godina = input.nextInt();
  100.         input.nextLine();
  101.  
  102.         Maraton m1 = new Maraton(mesto, godina, atleticari);
  103.         System.out.print(m1.toString());
  104.  
  105.         zemjaP = input.nextLine();
  106.         System.out.println("Prvo mesto: " + m1.najdobroVreme().toString());
  107.         System.out.println("Ima vkupno " + m1.atleticariOd(zemjaP) + " atleticar/i od " + zemjaP);
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement