Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.nio.file.Files;
- import java.nio.file.Paths;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.stream.Collectors;
- public class LerLista {
- public static void main(String[] args) {
- String fileName = "C:/Users/JOGOS/Documents/clinica.txt";
- List<String> list = new ArrayList<>();
- Integer qtd_pacientes = 0;
- Integer total_idade = 0;
- Integer qtd_homens = 0;
- Integer qtd_mulheres_alt_pes = 0;
- Integer qtd_pessoas_18_25 = 0;
- Integer maior_idade_h = 0;
- String paciente_mais_velho = "";
- Integer altura_mais_baixa_m = 1000;
- String mulher_mais_baixa = "";
- try (BufferedReader br = Files.newBufferedReader(Paths.get(fileName))) {
- list = br.lines().collect(Collectors.toList());
- for (String string : list) {
- String [] valores = string.split(";");
- qtd_pacientes ++;
- for (int i = 0; i < valores.length; i++) {
- switch (i) {
- case 0:
- if(valores[i].equals("fim")){
- i = valores.length;
- }
- break;
- case 1:
- if(valores[i].equals("M")){
- qtd_homens ++;
- }
- break;
- case 2:
- if (Integer.valueOf(valores[i]) >= 18 && Integer.valueOf(valores[i]) <= 25) {
- qtd_pessoas_18_25 ++;
- }
- if (Integer.parseInt(valores[i]) > maior_idade_h) {
- maior_idade_h = Integer.parseInt(valores[i]);
- paciente_mais_velho = valores[0];
- }
- if(valores[1].equals("M")){
- total_idade += Integer.valueOf(valores[i]);
- }
- break;
- case 4:
- if(valores[1].equals("F") && Integer.valueOf(valores[2]) > 70
- && Integer.valueOf(valores[i]) >= 160 && Integer.valueOf(valores [i]) <= 170){
- qtd_mulheres_alt_pes ++;
- }
- if(valores[1].equals("F") && Integer.valueOf(valores[i]) < altura_mais_baixa_m){
- altura_mais_baixa_m = Integer.valueOf(valores[i]);
- mulher_mais_baixa = valores[0];
- }
- break;
- default:
- break;
- }
- }
- }
- System.out.println("Quantidade de pacientes: " + qtd_pacientes);
- System.out.println("Média de idade dos homens: " + total_idade / qtd_homens);
- System.out.println("Quantidade de mulheres com altura entre 1,60 e 1,70 e peso acima de 70kg: " + qtd_mulheres_alt_pes);
- System.out.println("Quantidade de pessoas com idade entre 18 e 25: " + qtd_pessoas_18_25);
- System.out.println("Nome do paciente mais velho: " + paciente_mais_velho);
- System.out.println("Nome da mulher mais baixa: " + mulher_mais_baixa);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- On Wed, Apr 24, 2019 at 10:16 PM Otávio Remedio <otavioremedio@gmail.com> wrote:
- package teste;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.nio.file.Files;
- import java.nio.file.Paths;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.stream.Collectors;
- public class LerLista {
- public static void main(String[] args) {
- String fileName = "C:/Users/JOGOS/Documents/clinica.txt";
- List<String> list = new ArrayList<>();
- try (BufferedReader br = Files.newBufferedReader(Paths.get(fileName))) {
- //br returns as stream and convert it into a List
- list = br.lines().collect(Collectors.toList());
- for (String string : list) {
- String [] valores = string.split(";");
- for (int i = 0; i < valores.length; i++) {
- System.out.println(valores[i]);
- }
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- list.forEach(System.out::println);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement