Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- *@author: Dam Si
- *@web: http://miloshevski.us.to/
- */
- import java.util.Scanner;
- interface IMaraton {
- public Atleticar najdobroVreme();
- int atleticariOd(String s);
- }
- class Atleticar {
- private String ime;
- private String pol;
- private int vozrast;
- private double vremeIstrcuvanje;
- private String zemjaPoteklo;
- public Atleticar() {
- // TODO Auto-generated constructor stub
- }
- public Atleticar(String ime, String pol, int vozrast, double vremeIstrcuvanje, String zemjaPoteklo) {
- this.ime = ime;
- this.pol = pol;
- this.vozrast = vozrast;
- this.vremeIstrcuvanje = vremeIstrcuvanje;
- this.zemjaPoteklo = zemjaPoteklo;
- }
- public String getIme() {
- return ime;
- }
- public void setIme(String ime) {
- this.ime = ime;
- }
- public String getPol() {
- return pol;
- }
- public void setPol(String pol) {
- this.pol = pol;
- }
- public int getVozrast() {
- return vozrast;
- }
- public void setVozrast(int vozrast) {
- this.vozrast = vozrast;
- }
- public double getVremeIstrcuvanje() {
- return vremeIstrcuvanje;
- }
- public void setVremeIstrcuvanje(double vremeIstrcuvanje) {
- this.vremeIstrcuvanje = vremeIstrcuvanje;
- }
- public String getZemjaPoteklo() {
- return zemjaPoteklo;
- }
- public void setZemjaPoteklo(String zemjaPoteklo) {
- this.zemjaPoteklo = zemjaPoteklo;
- }
- @Override
- public String toString() {
- return String.format("%s\n%d\n%s\n%.1f", ime, vozrast, zemjaPoteklo, vremeIstrcuvanje);
- }
- }
- class Maraton implements IMaraton {
- private String mestoOddrzuvanje;
- private int godina;
- private Atleticar[] atleticari;
- public Maraton() {
- //default
- }
- public Maraton(String mestoOddrzuvanje, int godina, Atleticar[] atleticari) {
- this.mestoOddrzuvanje = mestoOddrzuvanje;
- this.godina = godina;
- this.atleticari = atleticari;
- }
- @Override
- public Atleticar najdobroVreme() {
- double min = Double.MAX_VALUE;
- int najdobar = 0;
- for(int i=0;i<atleticari.length;++i){
- if(atleticari[i].getVremeIstrcuvanje()<min){
- min = atleticari[i].getVremeIstrcuvanje();
- najdobar = i;
- }
- }
- return atleticari[najdobar];
- }
- @Override
- public int atleticariOd(String zemja) {
- int najdeno = 0;
- for (Atleticar a : atleticari) {
- if (a.getZemjaPoteklo().equals(zemja)) {
- ++najdeno;
- }
- }
- return najdeno;
- }
- @Override
- public String toString() {
- StringBuilder output = new StringBuilder();
- output.append(String.format("%s\n%d\n", getMestoOddrzuvanje(),getGodina()));
- for (int i = 0; i < atleticari.length; ++i) {
- output.append(atleticari[i].toString()).append("\n");
- }
- return output.toString();
- }
- public String getMestoOddrzuvanje() {
- return mestoOddrzuvanje;
- }
- public void setMestoOddrzuvanje(String mestoOddrzuvanje) {
- this.mestoOddrzuvanje = mestoOddrzuvanje;
- }
- public int getGodina() {
- return godina;
- }
- public void setGodina(int godina) {
- this.godina = godina;
- }
- public Atleticar[] getAtleticari() {
- return atleticari;
- }
- public void setAtleticari(Atleticar[] atleticari) {
- this.atleticari = atleticari;
- }
- }
- public class ZadacaMaraton {
- /**
- * @param args the command line arguments
- */
- 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