Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.Arrays;
- interface IMarathon {
- Athlete bestTime();
- int AthletesFrom(String s);
- }
- class Athlete{
- private String name;
- private String gender;
- private int age;
- private double time;
- private String country;
- public String getName() {
- return this.name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getGender() {
- return this.gender;
- }
- public void setGender(String gender) {
- this.gender = gender;
- }
- public int getAge() {
- return this.age;
- }
- public void setAge(int age) {
- this.age = age;
- }
- public double getTime() {
- return this.time;
- }
- public void setTime(double time) {
- this.time = time;
- }
- public String getCountry() {
- return this.country;
- }
- public void setCountry(String country) {
- this.country = country;
- }
- public Athlete(String name, String gender, int age, double time, String country) {
- super();
- this.name = name;
- this.gender = gender;
- this.age = age;
- this.time = time;
- this.country = country;
- }
- @Override
- public String toString() {
- return name + "\n" + age + "\n" + country + "\n" + time +"\n";
- }
- }
- class Marathon implements IMarathon {
- private String hostCountry;
- private int year;
- Athlete Athletes [] ;
- public String getHostCountry() {
- return this.hostCountry;
- }
- public void setHostCountry(String hostCountry) {
- this.hostCountry = hostCountry;
- }
- public int getYear() {
- return this.year;
- }
- public void setYear(int year) {
- this.year = year;
- }
- public Athlete [] getAthletes() {
- return this.Athletes;
- }
- public void setAthletes(Athlete [] Athletes) {
- this.Athletes = Athletes;
- }
- public Marathon(String hostCountry, int year, Athlete [] Athletes) {
- super();
- this.hostCountry = hostCountry;
- this.year = year;
- this.Athletes = Athletes;
- }
- @Override
- public String toString() {
- StringBuffer sb = new StringBuffer ();
- for(Athlete athlete : Athletes){
- sb.append(athlete.toString());
- }
- return hostCountry +"\n" + year + "\n" + sb.toString();
- }
- @Override
- public Athlete bestTime (){
- double min = 999999;
- int minIndex = 0 ;
- for( int i = 0; i < Athletes.length ; i ++){
- if(Athletes[i].getTime() < min){
- min = Athletes[i].getTime();
- minIndex= i;
- }
- }
- return Athletes[minIndex];
- }
- @Override
- public int AthletesFrom(String s){
- int count = 0;
- for(Athlete athlete : Athletes){
- if(athlete.getCountry().equals(s)){
- count++;
- }
- }
- return count;
- }
- }
- public class Test {
- public static void main (String [] args) {
- Scanner input=new Scanner(System.in);
- int n=input.nextInt();
- Athlete[] atleticari = new Athlete[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 Athlete(ime,pol,vozrast,vreme,zemja);
- }
- String mesto;
- int godina;
- String zemjaP;
- mesto = input.nextLine();
- godina = input.nextInt();
- input.nextLine();
- Marathon m1 = new Marathon(mesto, godina, atleticari);
- System.out.print(m1.toString());
- zemjaP = input.nextLine();
- System.out.println("Prvo mesto: " + m1.bestTime().toString());
- System.out.println("Ima vkupno " + m1.AthletesFrom(zemjaP) + " atleticar/i od " + zemjaP);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement