Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Marathon Problem 1 (1 / 9)
- Define Java interface IMarathon with the following methods:
- Athlete bestTime() - that returns the winner of the marathon
- int AthletesFrom(String s) - that returns the number of athletes from s country.
- Define Java class Athlete. For every athlete the following information is stored: name (String), gender (String), age (int), time score in seconds (double) and country of origin (String). For this class implement:
- constructors (default and with parameters)
- set and get methods
- the method toString() in the following format: name / age / country of origin / time score (all of the parameters should be split with one space)
- Define Java class Marathon that implements the interface IMarathon. For every marathon the following information is stored: host country (String), year (int), an array of Athletes Athlete[]. For this class implement:
- constructors (default and with parameters)
- set and get methods
- the method toString() in the following format: host country / year / attendees of the marathon (all of the parameters should be split with one space)
- bestTime()
- AthletesFrom(String s)
- Sample input
- 3
- Ana Anovska
- zenski
- 17
- 1207
- Makedonija
- Simon Simonovski
- maski
- 27
- 1200
- Srbija
- Andrea Andreeska
- zenski
- 25
- 1305
- Makedonija
- Skopje
- 2015
- Makedonija
- Sample output
- Skopje
- 2015
- Ana Anovska
- 17
- Makedonija
- 1207.0
- Simon Simonovski
- 27
- Srbija
- 1200.0
- Andrea Andreeska
- 25
- Makedonija
- 1305.0
- Prvo mesto: Simon Simonovski
- 27
- Srbija
- 1200.0
- Ima vkupno 2 atleticar/i od Makedonija */
- import java.util.Scanner;
- interface IMaraton
- {
- /**
- *
- * @return IMaraton е интерфејс кој има методи...
- */
- Athlete bestTime();
- int AthletesFrom(String s);
- }
- class Athlete
- {
- private String name;
- private String gender;
- private int age;
- private double time;
- public String state;
- public Athlete(String name, String gender, int age, double time, String state) {
- this.name = name;
- this.gender = gender;
- this.age = age;
- this.time = time;
- this.state = state;
- }
- public Athlete() {
- }
- public String getName() {
- return name;
- }
- public String getGender() {
- return gender;
- }
- public int getAge() {
- return age;
- }
- public double getTime() {
- return time;
- }
- public String getState() {
- return state;
- }
- public void setName(String name) {
- this.name = name;
- }
- public void setGender(String gender) {
- this.gender = gender;
- }
- public void setAge(int age) {
- this.age = age;
- }
- public void setTime(double time) {
- this.time = time;
- }
- public void setState(String state) {
- this.state = state;
- }
- @Override
- public String toString()
- {
- return name+"\n"+age+"\n"+state+"\n"+time;
- }
- }
- class Marathon implements IMaraton
- {
- private String host_country;
- private int year;
- private Athlete [] atleticari ;
- public Marathon(String host_country, int year, Athlete[] atleticari) {
- this.host_country = host_country;
- this.year = year;
- this.atleticari = atleticari;
- }
- public Marathon() {
- }
- public String getHost_country() {
- return host_country;
- }
- public int getYear() {
- return year;
- }
- public Athlete[] getAtleticari() {
- return atleticari;
- }
- public void setHost_country(String host_country) {
- this.host_country = host_country;
- }
- public void setYear(int year) {
- this.year = year;
- }
- public void setAtleticari(Athlete[] atleticari) {
- this.atleticari = atleticari;
- }
- @Override
- public Athlete bestTime() {
- double min = atleticari[0].getTime();
- int index= 0;
- for (int i = 0; i < atleticari.length; i++) {
- if(atleticari[i].getTime()<min)
- {
- min = atleticari[i].getTime();
- index = i;
- }
- }
- return atleticari[index];
- }
- @Override
- public int AthletesFrom(String s) {
- int br=0;
- for (int i = 0; i < atleticari.length; i++) {
- if(atleticari[i].getState().equals(s))
- br++;
- }
- return br;
- }
- @Override
- public String toString() {
- String s= new String();
- s = s+ host_country + "\n" + year+"\n" ;
- for (int i = 0; i < atleticari.length; i++) {
- s = s+atleticari[i].toString() + "\n";
- }
- return s;
- }
- }
- 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()+"\n");
- System.out.println("Ima vkupno " + m1.AthletesFrom(zemjaP) + " atleticar/i od " + zemjaP);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement