Advertisement
WallHero

TP04E05 MainClass

Oct 30th, 2020
1,768
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.14 KB | None | 0 0
  1. package tp;
  2.  
  3. import java.text.ParseException;
  4. import java.text.SimpleDateFormat;
  5. import java.util.Date;
  6.  
  7. public class PuntoCinco {
  8.      
  9.     public static void main(String[] args) {
  10.         new PuntoCinco().run();
  11.     }
  12.    
  13.     void run()
  14.     {
  15.         Lista lista = new Lista();
  16.         while(true)
  17.         {
  18.             int op = Helper.forceReadRangeInteger("Elija opción:\n1-Registrar información de Paciente\n2-Mostrar datos de Pacientes.", 1, 2);
  19.             if(op == 1) registrarPaciente(lista);
  20.             else mostrarLista(lista);
  21.             if(!Helper.continueInput("¿Continuará la ejecución? (S/N)")) break;
  22.         }
  23.        
  24.     }
  25.    
  26.    
  27.     void mostrarLista(Lista lista)
  28.     {
  29.         if(lista.getPrimero()==null) {
  30.             System.out.println("La lista de pacientes está vacía.");
  31.         }else {
  32.             lista.mostrarLista();
  33.         }
  34.     }
  35.    
  36.     void registrarPaciente(Lista lista)
  37.     {
  38.         boolean random = Helper.isRandom();
  39.         String nombre, apellido, sexo, servicio, domicilio;
  40.         Date fecha = new Date();
  41.         int edad;
  42.         String[] sexos = {"Hombre", "Mujer", "Otro"};
  43.         String[] servicios = {"Curación", "Control", "Nebulización", "Vacunación"};
  44.         while(true)
  45.         {
  46.             if(random)
  47.             {
  48.                 nombre = Helper.generateRandomString();
  49.                 apellido = Helper.generateRandomString();
  50.                 domicilio = Helper.generateRandomString();
  51.                 sexo = sexos[Helper.getRandomIntBetweenRange(0, 2)];
  52.                 edad = Helper.getRandomIntBetweenRange(1, 100);          
  53.                 servicio = servicios[Helper.getRandomIntBetweenRange(0, 3)];
  54.                 SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
  55.                 String randFecha = Helper.getRandomIntBetweenRange(1, 28) + "/" + Helper.getRandomIntBetweenRange(1, 12) + "/" + Helper.getRandomIntBetweenRange(2000, 2020);
  56.                 try {
  57.                     fecha = sdf.parse(randFecha);
  58.                 } catch (ParseException e) {
  59.                     System.out.println();
  60.                 }
  61.                 System.out.println("Paciente generado. \n");
  62.             }
  63.             else
  64.             {
  65.                 System.out.println("Introduzca el nombre del paciente:");
  66.                 nombre = Helper.scanner.next();
  67.                 System.out.println("Introduzca el apellido del paciente:");
  68.                 apellido = Helper.scanner.next();
  69.                 sexo = sexos[Helper.forceReadRangeInteger("¿Sexo? 1-Hombre\t2-Mujer\t3-Otro", 1, 3)-1];
  70.                 edad = Helper.forceReadPositiveInteger("¿Edad?");            
  71.                 servicio = servicios[Helper.forceReadRangeInteger("¿Preferencia? 1-Curación\t2-Control\t3-Nebulización\t4-Vacunación", 1, 4)-1];
  72.                 System.out.println("Introduzca el domicilio del paciente:");
  73.                 domicilio = Helper.scanner.next();
  74.                 fecha = Helper.readDate();
  75.             }
  76.             Paciente paciente = new Paciente(nombre,apellido,sexo,edad,servicio,domicilio, fecha);
  77.             lista.insertarCabezaLista(paciente);
  78.             if(!Helper.continueInput("¿Continuará cargando pacientes? (S/N)")) return;
  79.         }
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement