Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class AtletasMooshak {
- private Atleta[] atleta;
- public void leAtleta() {
- Scanner sc = new Scanner(System.in);
- int n = Integer.parseInt(sc.nextLine());
- atleta = new Atleta[n];
- for (int i = 0; i < n; i++) {
- atleta[i] = new Atleta(sc.next(), new int[]{sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt()});
- atleta[i].calcularTotal();
- }
- }
- public void ordenaAtleta() {
- Atleta temp;
- for (int i = 0; i < atleta.length; i++) {
- for (int j = 0; j < atleta.length - 1; j++) {
- if (atleta[j].comparaTotalCom(atleta[j + 1]) > 0) {
- temp = atleta[j];
- atleta[j] = atleta[j + 1];
- atleta[j + 1] = temp;
- }
- }
- }
- }
- public void escreve() {
- for (int i = 0; i < atleta.length; i++) {
- System.out.print(atleta[i].getNome());
- System.out.print(" ");
- System.out.println(atleta[i].getTotal());
- }
- }
- public static void main(String[] args) {
- AtletasMooshak am = new AtletasMooshak();
- am.leAtleta();
- am.ordenaAtleta();
- am.escreve();
- }
- }
- class Atleta {
- private String nome;
- private int[] tempos;
- private int total = 0;
- public Atleta(String nome, int[] tempos) {
- this.nome = nome;
- for (int i = 0; i < tempos.length; i++) {
- this.tempos = tempos;
- }
- }
- public String getNome() {
- return nome;
- }
- public void setNome(String nome) {
- this.nome = nome;
- }
- public int getTotal() {
- return total;
- }
- public void setTotal(int total) {
- this.total = total;
- }
- public void calcularTotal() {
- for (int i = 0; i < tempos.length; i++) {
- total += tempos[i];
- }
- }
- public int comparaTotalCom(Atleta a) {
- return total - a.getTotal();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement