Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.Arrays;
- 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);
- }
- }
- class Atleticar {
- private String name;
- private String sex;
- private int age;
- private double timeInSeconds;
- private String country;
- public Atleticar() {
- name = "";
- sex = "";
- age = 0;
- timeInSeconds = 0;
- country = "";
- }
- public Atleticar(String name, String sex, int age, double timeInSeconds, String country) {
- this.name = name;
- this.sex = sex;
- this.age = age;
- this.timeInSeconds = timeInSeconds;
- this.country = country;
- }
- public void setName(String name) {
- this.name = name;
- }
- public void setAge(int age) {
- this.age = age;
- }
- public void setCountry(String country) {
- this.country = country;
- }
- public void setSex(String sex) {
- this.sex = sex;
- }
- public void setTimeInSeconds(double timeInSeconds) {
- this.timeInSeconds = timeInSeconds;
- }
- public String getName() {
- return name;
- }
- public double getTimeInSeconds() {
- return timeInSeconds;
- }
- public int getAge() {
- return age;
- }
- public String getCountry() {
- return country;
- }
- public String getSex() {
- return sex;
- }
- public String toString() {
- return this.name + "\n" + this.age + "\n" + this.country + "\n" + this.timeInSeconds + "\n";
- }
- }
- class Maraton implements IMaraton {
- private String maratonCountry;
- private int year;
- private Atleticar[] atleticari;
- public Maraton() {}
- public Maraton(String maratonCountry, int year, Atleticar[] atleticari) {
- this.maratonCountry = maratonCountry;
- this.year = year;
- this.atleticari = Arrays.copyOf(atleticari, atleticari.length);
- }
- public void setYear(int year) {
- this.year = year;
- }
- public void setAtleticari(Atleticar[] atleticari) {
- this.atleticari = Arrays.copyOf(atleticari, atleticari.length);
- }
- public void setMaratonCountry(String maratonCountry) {
- this.maratonCountry = maratonCountry;
- }
- public Atleticar[] getAtleticari() {
- return Arrays.copyOf(atleticari, atleticari.length);
- }
- public int getYear() {
- return year;
- }
- public String getMaratonCountry() {
- return maratonCountry;
- }
- public String toString() {
- StringBuilder stringBuilder = new StringBuilder();
- stringBuilder.append(maratonCountry).append("\n").append(year).append("\n");
- for (Atleticar atleticar : atleticari) {
- stringBuilder.append(atleticar.toString());
- }
- return stringBuilder.toString();
- }
- @Override
- public Atleticar najdobroVreme() {
- double bestTime = atleticari[0].getTimeInSeconds();
- int index = 0;
- for (int i = 0; i < atleticari.length; i++) {
- if (bestTime > atleticari[i].getTimeInSeconds()) {
- bestTime = atleticari[i].getTimeInSeconds();
- index = i;
- }
- }
- return atleticari[index];
- }
- @Override
- public int atleticariOd(String s) {
- int count = 0;
- for (Atleticar atleticar : atleticari) {
- if (atleticar.getCountry().equals(s)) count++;
- }
- return count;
- }
- }
- interface IMaraton {
- public Atleticar najdobroVreme();
- public int atleticariOd(String s);
- }
Add Comment
Please, Sign In to add comment