Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.nio.file.Files;
  4. import java.nio.file.Paths;
  5. import java.util.ArrayList;
  6. import java.util.List;
  7. import java.util.stream.Collectors;
  8.  
  9. public class LerLista {
  10.  
  11. public static void main(String[] args) {
  12.  
  13. String arquivo = "C:/Users/JOGOS/Documents/clinica.txt";
  14. List<String> lista = new ArrayList<>();
  15. Integer qtd_pacientes = 0;
  16. Integer total_idade = 0;
  17. Integer qtd_homens = 0;
  18. Integer qtd_mulheres_alt_pes = 0;
  19. Integer qtd_pessoas_18_25 = 0;
  20. Integer maior_idade_h = 0;
  21. String paciente_mais_velho = "";
  22. Integer altura_mais_baixa_m = 1000;
  23. String mulher_mais_baixa = "";
  24.  
  25. try (BufferedReader br = Files.newBufferedReader(Paths.get(arquivo))) {
  26.  
  27. lista = br.lines().collect(Collectors.toList());
  28.  
  29. for (String string : lista) {
  30. String [] valores = string.split(";");
  31. qtd_pacientes ++;
  32. for (int i = 0; i < valores.length; i++) {
  33.  
  34. switch (i) {
  35. case 0:
  36. if(valores[i].equals("fim")){
  37. i = valores.length;
  38. }
  39. break;
  40.  
  41. case 1:
  42. if(valores[i].equals("M")){
  43. qtd_homens ++;
  44. }
  45. break;
  46.  
  47. case 2:
  48. if (Integer.valueOf(valores[i]) >= 18 && Integer.valueOf(valores[i]) <= 25) {
  49. qtd_pessoas_18_25 ++;
  50. }
  51.  
  52. if (Integer.parseInt(valores[i]) > maior_idade_h) {
  53. maior_idade_h = Integer.parseInt(valores[i]);
  54. paciente_mais_velho = valores[0];
  55. }
  56.  
  57. if(valores[1].equals("M")){
  58. total_idade += Integer.valueOf(valores[i]);
  59. }
  60.  
  61. break;
  62.  
  63. case 4:
  64. if(valores[1].equals("F") && Integer.valueOf(valores[2]) > 70
  65. && Integer.valueOf(valores[i]) >= 160 && Integer.valueOf(valores [i]) <= 170){
  66. qtd_mulheres_alt_pes ++;
  67. }
  68.  
  69. if(valores[1].equals("F") && Integer.valueOf(valores[i]) < altura_mais_baixa_m){
  70. altura_mais_baixa_m = Integer.valueOf(valores[i]);
  71. mulher_mais_baixa = valores[0];
  72. }
  73.  
  74. break;
  75.  
  76. default:
  77. break;
  78. }
  79. }
  80. }
  81.  
  82. System.out.println("Quantidade de pacientes: " + qtd_pacientes);
  83. System.out.println("Média de idade dos homens: " + total_idade / qtd_homens);
  84. System.out.println("Quantidade de mulheres com altura entre 1,60 e 1,70 e peso acima de 70kg: " + qtd_mulheres_alt_pes);
  85. System.out.println("Quantidade de pessoas com idade entre 18 e 25: " + qtd_pessoas_18_25);
  86. System.out.println("Nome do paciente mais velho: " + paciente_mais_velho);
  87. System.out.println("Nome da mulher mais baixa: " + mulher_mais_baixa);
  88.  
  89. } catch (IOException e) {
  90. e.printStackTrace();
  91. }
  92.  
  93. }
  94.  
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement