Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- interface IMaraton {
- public Atleticar najdobroVreme();
- public int atleticariOd(String s);
- }
- class Atleticar{
- private String ime;
- private String pol;
- private int vozrast;
- private double vreme;
- private String poteklo;
- Atleticar(){}
- Atleticar(String ime, String pol, int vozrast, double vreme, String poteklo){
- this.ime = ime;
- this.pol = pol;
- this.vozrast = vozrast;
- this.vreme = vreme;
- this.poteklo = poteklo;
- }
- /*toString() - формат: име / возраст / земја на потекло / време на истрчување (сите параметри одделени со празно место)*/
- @Override
- public String toString(){
- return ime + "\n" + vozrast + "\n" + poteklo + "\n" + vreme + "\n";
- }
- double getVreme(){return vreme;}
- String getPoteklo(){return poteklo;}
- }
- class Maraton implements IMaraton{
- private String mesto;
- private int godina;
- private Atleticar [] atleticari;
- Maraton(){}
- Maraton(String mesto, int godina, Atleticar [] atleticari){
- this.mesto = mesto;
- this.godina = godina;
- this.atleticari = atleticari;
- }
- @Override
- public String toString(){
- StringBuilder rez = new StringBuilder(mesto + "\n" + godina + "\n");
- for(Atleticar m : atleticari)
- rez.append(m.toString());
- return(rez.toString());
- }
- @Override
- public Atleticar najdobroVreme() {
- Atleticar najdobar = atleticari[0];
- for(Atleticar x : atleticari){
- if(x.getVreme() < najdobar.getVreme())
- najdobar = x;
- }
- return najdobar;
- }
- @Override
- public int atleticariOd(String s) {
- int od = 0;
- for(Atleticar x : atleticari){
- if(x.getPoteklo().equals(s))
- od++;
- }
- return od;
- }
- }
- public class ZadacaMaraton {
- public static void main(String[] args) {
- Scanner input=new Scanner(System.in);
- int n=input.nextInt();
- Atleticar[] atleticari = new Atleticar[n];
- String ime;
- String pol;
- int vozrast;
- double vreme;
- String zemja;
- input.nextLine();
- for(int i=0;i<n;i++)
- {
- ime = input.nextLine();
- pol = input.nextLine();
- vozrast = input.nextInt();
- vreme = input.nextDouble();
- input.nextLine();
- zemja = input.nextLine();
- atleticari[i]=new Atleticar(ime,pol,vozrast,vreme,zemja);
- }
- String mesto;
- int godina;
- String zemjaP;
- mesto = input.nextLine();
- godina = input.nextInt();
- input.nextLine();
- Maraton m1 = new Maraton(mesto, godina, atleticari);
- System.out.print(m1.toString());
- zemjaP = input.nextLine();
- System.out.println("Prvo mesto: " + m1.najdobroVreme().toString());
- System.out.println("Ima vkupno " + m1.atleticariOd(zemjaP) + " atleticar/i od " + zemjaP);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement