DamSi

Untitled

Oct 14th, 2015
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.79 KB | None | 0 0
  1. /*
  2. *@author: Dam Si
  3. *@web: http://miloshevski.us.to/
  4. */
  5. import java.util.Scanner;
  6.  
  7. interface IMaraton {
  8.         public Atleticar najdobroVreme();
  9.  
  10.         int atleticariOd(String s);
  11. }
  12.  
  13. class Atleticar {
  14.         private String ime;
  15.         private String pol;
  16.         private int vozrast;
  17.         private double vremeIstrcuvanje;
  18.         private String zemjaPoteklo;
  19.  
  20.         public Atleticar() {
  21.                 // TODO Auto-generated constructor stub
  22.         }
  23.  
  24.         public Atleticar(String ime, String pol, int vozrast, double vremeIstrcuvanje, String zemjaPoteklo) {
  25.                 this.ime = ime;
  26.                 this.pol = pol;
  27.                 this.vozrast = vozrast;
  28.                 this.vremeIstrcuvanje = vremeIstrcuvanje;
  29.                 this.zemjaPoteklo = zemjaPoteklo;
  30.         }
  31.  
  32.         public String getIme() {
  33.                 return ime;
  34.         }
  35.  
  36.         public void setIme(String ime) {
  37.                 this.ime = ime;
  38.         }
  39.  
  40.         public String getPol() {
  41.                 return pol;
  42.         }
  43.  
  44.         public void setPol(String pol) {
  45.                 this.pol = pol;
  46.         }
  47.  
  48.         public int getVozrast() {
  49.                 return vozrast;
  50.         }
  51.  
  52.         public void setVozrast(int vozrast) {
  53.                 this.vozrast = vozrast;
  54.         }
  55.  
  56.         public double getVremeIstrcuvanje() {
  57.                 return vremeIstrcuvanje;
  58.         }
  59.  
  60.         public void setVremeIstrcuvanje(double vremeIstrcuvanje) {
  61.                 this.vremeIstrcuvanje = vremeIstrcuvanje;
  62.         }
  63.  
  64.         public String getZemjaPoteklo() {
  65.                 return zemjaPoteklo;
  66.         }
  67.  
  68.         public void setZemjaPoteklo(String zemjaPoteklo) {
  69.                 this.zemjaPoteklo = zemjaPoteklo;
  70.         }
  71.  
  72.         @Override
  73.         public String toString() {
  74.                 return String.format("%s\n%d\n%s\n%.1f", ime, vozrast, zemjaPoteklo, vremeIstrcuvanje);
  75.         }
  76.  
  77. }
  78.  
  79. class Maraton implements IMaraton {
  80.         private String mestoOddrzuvanje;
  81.         private int godina;
  82.         private Atleticar[] atleticari;
  83.  
  84.         public Maraton() {
  85.                 //default
  86.         }
  87.  
  88.         public Maraton(String mestoOddrzuvanje, int godina, Atleticar[] atleticari) {
  89.                 this.mestoOddrzuvanje = mestoOddrzuvanje;
  90.                 this.godina = godina;
  91.                 this.atleticari = atleticari;
  92.         }
  93.  
  94.         @Override
  95.         public Atleticar najdobroVreme() {
  96.                 double min = Double.MAX_VALUE;
  97.                 int najdobar = 0;
  98.                 for(int i=0;i<atleticari.length;++i){
  99.                         if(atleticari[i].getVremeIstrcuvanje()<min){
  100.                                 min = atleticari[i].getVremeIstrcuvanje();
  101.                                 najdobar = i;
  102.                         }
  103.                 }
  104.                 return atleticari[najdobar];
  105.         }
  106.  
  107.         @Override
  108.         public int atleticariOd(String zemja) {
  109.                 int najdeno = 0;
  110.                 for (Atleticar a : atleticari) {
  111.                         if (a.getZemjaPoteklo().equals(zemja)) {
  112.                                 ++najdeno;
  113.                         }
  114.                 }
  115.                 return najdeno;
  116.         }
  117.  
  118.         @Override
  119.         public String toString() {
  120.                 StringBuilder output = new StringBuilder();
  121.                 output.append(String.format("%s\n%d\n", getMestoOddrzuvanje(),getGodina()));
  122.                 for (int i = 0; i < atleticari.length; ++i) {
  123.                         output.append(atleticari[i].toString()).append("\n");
  124.                 }
  125.                 return output.toString();
  126.         }
  127.  
  128.         public String getMestoOddrzuvanje() {
  129.                 return mestoOddrzuvanje;
  130.         }
  131.  
  132.         public void setMestoOddrzuvanje(String mestoOddrzuvanje) {
  133.                 this.mestoOddrzuvanje = mestoOddrzuvanje;
  134.         }
  135.  
  136.         public int getGodina() {
  137.                 return godina;
  138.         }
  139.  
  140.         public void setGodina(int godina) {
  141.                 this.godina = godina;
  142.         }
  143.  
  144.         public Atleticar[] getAtleticari() {
  145.                 return atleticari;
  146.         }
  147.  
  148.         public void setAtleticari(Atleticar[] atleticari) {
  149.                 this.atleticari = atleticari;
  150.         }
  151.        
  152. }
  153. public class ZadacaMaraton {
  154.  
  155.     /**
  156.      * @param args the command line arguments
  157.      */
  158.     public static void main(String[] args) {
  159.         Scanner input = new Scanner(System.in);
  160.                 int n = input.nextInt();
  161.                 Atleticar[] atleticari = new Atleticar[n];
  162.  
  163.                 String ime;
  164.                 String pol;
  165.                 int vozrast;
  166.                 double vreme;
  167.                 String zemja;
  168.  
  169.                 input.nextLine();
  170.  
  171.                 for (int i = 0; i < n; i++) {
  172.                         ime = input.nextLine();
  173.                         pol = input.nextLine();
  174.                         vozrast = input.nextInt();
  175.                         vreme = input.nextDouble();
  176.                         input.nextLine();
  177.                         zemja = input.nextLine();
  178.                         atleticari[i] = new Atleticar(ime, pol, vozrast, vreme, zemja);
  179.                 }
  180.  
  181.                 String mesto;
  182.                 int godina;
  183.                 String zemjaP;
  184.                 mesto = input.nextLine();
  185.                 godina = input.nextInt();
  186.                 input.nextLine();
  187.  
  188.                 Maraton m1 = new Maraton(mesto, godina, atleticari);
  189.                 System.out.print(m1.toString());
  190.  
  191.                 zemjaP = input.nextLine();
  192.                 System.out.println("Prvo mesto: " + m1.najdobroVreme().toString());
  193.                 System.out.println("Ima vkupno " + m1.atleticariOd(zemjaP) + " atleticar/i od " + zemjaP);
  194.     }
  195.    
  196. }
Advertisement
Add Comment
Please, Sign In to add comment