Advertisement
Guest User

Untitled

a guest
Dec 10th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.26 KB | None | 0 0
  1. package runners2016;
  2.  
  3. import java.text.DateFormat;
  4. import java.text.SimpleDateFormat;
  5. import java.util.Date;
  6. import java.util.Scanner;
  7.  
  8. public class utilitarios {
  9.  
  10.     public static void pausa() {
  11.         Scanner in = new Scanner(System.in);
  12.         System.out.println("\n\nPara continuar prima ENTER");
  13.         in.nextLine();
  14.     }
  15.  
  16.     public static String dataAtual() {
  17.         DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
  18.         Date d = new Date();
  19.         String data = dateFormat.format(d);
  20.         return data;
  21.     }
  22.  
  23.     @SuppressWarnings("ManualArrayToCollectionCopy")
  24.     public static void ordenarAlfabeticamente(String[][] socios, int[][] tempos, int nSocios, int N_CAMPOS_INFO, int N_PROVAS) {
  25.         String tmpS;
  26.         int tmpI;
  27.         for (int i = 0; i < nSocios - 1; i++) {
  28.             for (int j = i; j < nSocios; j++) {
  29.                 if (socios[i][1].compareTo(socios[j][1]) > 0) {
  30.                     for (int k = 0; k < N_CAMPOS_INFO; k++) {
  31.                         tmpS = socios[i][k];
  32.                         socios[i][k] = socios[j][k];
  33.                         socios[j][k] = tmpS;
  34.                     }
  35.                     for (int x = 0; x < N_PROVAS; x++) {
  36.                         tmpI = tempos[i][x];
  37.                         tempos[i][x] = tempos[j][x];
  38.                         tempos[j][x] = tmpI;
  39.                     }
  40.                 }
  41.             }
  42.         }
  43.     }
  44.  
  45.     public static int calcularIdade(String[][] socios, int i) {
  46.         String[] dataHoje = dataAtual().trim().split("/");
  47.         String[] dataNasc = socios[i][2].trim().split("/");
  48.         int AnoNas = Integer.parseInt(dataNasc[2]);
  49.         int AnoAct = Integer.parseInt(dataHoje[2]);
  50.         int idade = AnoAct - AnoNas;
  51.         if (dataHoje[1].compareTo(dataNasc[1]) < 0) {
  52.             idade--;
  53.         }
  54.         if (dataHoje[1].equals(dataNasc[1])) {
  55.             if (dataHoje[0].compareTo(dataNasc[0]) < 0) {
  56.                 idade--;
  57.             }
  58.  
  59.         }
  60.  
  61.         return idade;
  62.     }
  63.  
  64.     public static String primeiroUltimoNome(String[][] socios, int nSocios, int pos) {
  65.         String[] temp = socios[pos][1].split(" ");
  66.         String nome = temp[0] + " " + temp[temp.length - 1];
  67.         return nome;
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement