Advertisement
matias626

class Punto05_TP4

Oct 29th, 2020
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.29 KB | None | 0 0
  1. import java.util.Calendar;
  2. import java.util.Date;
  3. import java.util.GregorianCalendar;
  4. import java.util.Iterator;
  5. import java.util.Random;
  6. import java.util.Scanner;
  7.  
  8.  
  9. public class Punto05_TP4 {
  10.    
  11.     static Scanner ingreso= new Scanner(System.in);
  12.     static Random aleatorio=new Random();
  13.     public static void main(String[] args) {
  14.  
  15.      ejecutar();          
  16.        
  17.     }
  18.     public static void ejecutar() {
  19.         SimpleLinkedList<Paciente> pacientes= new SimpleLinkedList<Paciente>();
  20.  
  21.         int opcion;
  22.        
  23.         do {
  24.            opcion=menu();
  25.            
  26.            switch(opcion){
  27.            
  28.            case 1:
  29.                    cargaManual(pacientes);
  30.                break;
  31.            
  32.            case 2:
  33.                       cargaAleatoria(pacientes);
  34.               break;
  35.                
  36.            case 3:
  37.                    mostrarResultados(pacientes);
  38.                    break;
  39.            }
  40.        }while(opcion!=4);
  41.         System.out.println("Fin del Programa");
  42.     }
  43.    
  44.     public static int menu() {
  45.        
  46.         int opcion;
  47.          System.out.println("Menu");
  48.          System.out.println("1: Ingreso de pacientes manualmente");
  49.          System.out.println("2: Generar pacientes aleatoriamente");
  50.          System.out.println("3: Imprimir pacientes");
  51.          System.out.println("4: Salir del programa");
  52.          
  53.          do{
  54.              opcion= Helper.validarEntero(ingreso, "Ingrese una opcion 1,2,3 o 4:\n ");
  55.          }while (opcion>4 ||opcion<=0);
  56.          return opcion;
  57.      }
  58.    
  59.     private static String[]algunServicio= {"Curacion", "Control", "Nebulizacion", "Vacunaciom"};
  60.     private static String[] algunApellido= {"Alanis","Azurduy","Fernandez","Flores","Pizarro"};
  61.     private static String[] algunNombre= {"Santiago","Victor","Nahuel","Daniel", "Matias"};
  62.     private static Character[] algunSexo={'M','F'};
  63.     private static String[] algunDomicilio= {"Huaico N° 1295","Perales N° 1234", "San Martin N° 1059", "Belgrano N° 1207"};
  64.    
  65.     public static String servicioPrestado(String mensaje) {
  66.         int opcion;
  67.         String respuesta="";
  68.        
  69.         do {
  70.             opcion=Helper.enteroPositivo(ingreso, mensaje);
  71.             switch (opcion){
  72.             case 1:
  73.                 respuesta="Curacion";
  74.                 break;
  75.             case 2:
  76.                 respuesta="Control";
  77.                 break;
  78.             case 3:
  79.                 respuesta="Nebulizacion";
  80.                 break;
  81.             case 4:
  82.                 respuesta= "Vacunacion";
  83.                 break;
  84.             }
  85.             if (opcion>=5) {
  86.                 System.out.println("Debe elegir 1, 2, 3 o 4");
  87.             }
  88.         }while (opcion>=5);
  89.         return respuesta;
  90.     }
  91.     public static void cargaManual(SimpleLinkedList<Paciente> pacientes) {
  92.        
  93.         Calendar calendario=new GregorianCalendar();
  94.         String respuesta="s";
  95.         int edad,dia,mes,anio;
  96.         Character sexo;
  97.        
  98.         while (respuesta.equalsIgnoreCase("s")) {
  99.                 String nombre=Helper.cadena("Ingrese su nombre:");
  100.                 String apellido=Helper.cadena("Ingrese su apellido:");
  101.                
  102.                 do {
  103.                  edad=Helper.enteroPositivo(ingreso, "Ingrese su edad: ");
  104.                 }while(edad>100);
  105.                
  106.                 do {
  107.                  sexo=Helper.validarCaracter(ingreso, "Ingrese su sexo  M o F: " );
  108.                 sexo=sexo.toUpperCase(sexo);
  109.                 }while(sexo!='M'&&sexo!='F');
  110.                 String domicilio =Helper.cadena("Ingrese su domicilio calle y numero:  ");
  111.                 String servicioPrestado=servicioPrestado("Seleccione servicio prestado: \n1: Curacion\n2: Control\n3: Nebulizacion\n4: Vacunacion");
  112.                
  113.                 do {
  114.                 dia=Helper.enteroPositivo(ingreso, "Ingrese el dia: ");
  115.                 }while(dia>31);
  116.                
  117.                 do {
  118.                  mes=Helper.enteroPositivo(ingreso, "Ingrese el mes en numero: ");
  119.                 }while(mes>12);
  120.                
  121.                 do {
  122.                  anio=Helper.enteroPositivo(ingreso, "Ingrese el año: ");
  123.                 }while(anio<2010 || anio>2020);
  124.                   mes--;
  125.                   calendario.set(anio, mes, dia);
  126.                   Date fecha =calendario.getTime();
  127.                 Paciente lista=new Paciente(nombre, apellido, sexo, edad, domicilio, fecha, servicioPrestado);
  128.                 pacientes.agregarFinal(lista);
  129.                 System.out.println("Paciente \n"+lista);  
  130.              respuesta=Helper.respuestaSiNo(ingreso, "Desea ingresar otro paciente s/n: ");
  131.          }
  132.          
  133.          System.out.println("Pacientes cargados");
  134.    
  135.     }
  136.     public static void cargaAleatoria(SimpleLinkedList<Paciente> pacientes) {
  137.        
  138.         Calendar calendario=new GregorianCalendar();
  139.         String respuesta="s";
  140.        
  141.         while (respuesta.equalsIgnoreCase("s")) {
  142.                 String nombre=algunNombre[aleatorio.nextInt(algunNombre.length)];
  143.                 String apellido=algunApellido[aleatorio.nextInt(algunApellido.length)];
  144.                 Integer edad=Helper.generaNumeroInt(100, 1);
  145.                 Character sexo=algunSexo[aleatorio.nextInt(algunSexo.length)];
  146.                 String domicilio =algunDomicilio[aleatorio.nextInt(algunDomicilio.length)];
  147.                 String servicioPrestado=algunServicio[aleatorio.nextInt(algunServicio.length)];
  148.                
  149.                 int dia=Helper.generaNumeroInt(30, 1);
  150.                 int mes=Helper.generaNumeroInt(12, 1);
  151.                 int anio=2020;
  152.                   mes--;
  153.                   calendario.set(anio, mes, dia);
  154.                   Date fecha =calendario.getTime();
  155.                 Paciente lista=new Paciente(nombre, apellido, sexo, edad, domicilio, fecha, servicioPrestado);
  156.                 pacientes.agregarFinal(lista);
  157.                 System.out.println("Paciente generado \n"+lista);  
  158.              respuesta=Helper.respuestaSiNo(ingreso, "Desea generar  otro paciente s/n: ");
  159.          }
  160.          
  161.          System.out.println("Pacientes cargados");
  162.  
  163.     }
  164.     public static void mostrarResultados(SimpleLinkedList<Paciente> pacientes) {
  165.        
  166.         int menorDe13=0;
  167.         int curaciones=0;
  168.         int controles=0;
  169.         int nebulizaciones=0;
  170.         int vacunaciones=0;
  171.         int contador=0;
  172.        
  173.         System.out.println("Lista de Pacientes:");
  174.         Iterator<Paciente> iterador=pacientes.iterator();
  175.        
  176.         while(iterador.hasNext()) {
  177.             ++contador;
  178.             Paciente paciente= iterador.next();
  179.             System.out.println("Paciente "+contador+": "+paciente);
  180.             if (paciente.getEdad()<13) {
  181.                 menorDe13++;
  182.             }
  183.            
  184.             switch (paciente.getServicioPrestado()) {
  185.            
  186.             case "Curacion":
  187.                 curaciones++;
  188.                 break;
  189.            
  190.             case "Control":
  191.                 controles++;
  192.                 break;
  193.            
  194.             case "Nebulizacion":
  195.                 nebulizaciones++;
  196.                 break;
  197.            
  198.             case "Vacunacion":
  199.                 vacunaciones++;
  200.                 break;
  201.             }  
  202.         }
  203.        
  204.         System.out.println("Cantidad de niños menores de 13: "+ menorDe13);
  205.         System.out.println("Cantidad de Curaciones: "+curaciones);
  206.         System.out.println("Cantidad de Controles: "+controles);
  207.        
  208.         if (nebulizaciones>vacunaciones) {
  209.             System.out.println("La cantidad de nebulizaciones supera a la cantidad de vacunaciones\n"+"Nebulizaciones: "+nebulizaciones+" Vacunaciones: "+vacunaciones);
  210.         }
  211.            
  212.     }
  213. }
  214.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement