Advertisement
dfilipeloja

Exercicio 3 Mooshak

Apr 12th, 2015
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.07 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class AtletasMooshak {
  4.  
  5.     private Atleta[] atleta;
  6.  
  7.     public void leAtleta() {
  8.         Scanner sc = new Scanner(System.in);
  9.         int n = Integer.parseInt(sc.nextLine());
  10.  
  11.         atleta = new Atleta[n];
  12.         for (int i = 0; i < n; i++) {
  13.             atleta[i] = new Atleta(sc.next(), new int[]{sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt()});
  14.             atleta[i].calcularTotal();
  15.         }
  16.     }
  17.  
  18.     public void ordenaAtleta() {
  19.         Atleta temp;
  20.  
  21.         for (int i = 0; i < atleta.length; i++) {
  22.             for (int j = 0; j < atleta.length - 1; j++) {
  23.                 if (atleta[j].comparaTotalCom(atleta[j + 1]) > 0) {
  24.                     temp = atleta[j];
  25.                     atleta[j] = atleta[j + 1];
  26.                     atleta[j + 1] = temp;
  27.                 }
  28.             }
  29.         }
  30.     }
  31.  
  32.     public void escreve() {
  33.         for (int i = 0; i < atleta.length; i++) {
  34.             System.out.print(atleta[i].getNome());
  35.             System.out.print(" ");
  36.             System.out.println(atleta[i].getTotal());
  37.         }
  38.     }
  39.  
  40.     public static void main(String[] args) {
  41.         AtletasMooshak am = new AtletasMooshak();
  42.         am.leAtleta();
  43.         am.ordenaAtleta();
  44.         am.escreve();
  45.     }
  46. }
  47.  
  48. class Atleta {
  49.  
  50.     private String nome;
  51.     private int[] tempos;
  52.     private int total = 0;
  53.  
  54.     public Atleta(String nome, int[] tempos) {
  55.         this.nome = nome;
  56.  
  57.         for (int i = 0; i < tempos.length; i++) {
  58.             this.tempos = tempos;
  59.         }
  60.     }
  61.  
  62.     public String getNome() {
  63.         return nome;
  64.     }
  65.  
  66.     public void setNome(String nome) {
  67.         this.nome = nome;
  68.     }
  69.  
  70.     public int getTotal() {
  71.         return total;
  72.     }
  73.  
  74.     public void setTotal(int total) {
  75.         this.total = total;
  76.     }
  77.  
  78.     public void calcularTotal() {
  79.         for (int i = 0; i < tempos.length; i++) {
  80.             total += tempos[i];
  81.         }
  82.     }
  83.  
  84.     public int comparaTotalCom(Atleta a) {
  85.         return total - a.getTotal();
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement