Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Calendar;
- import java.util.Date;
- import java.util.GregorianCalendar;
- import java.util.Iterator;
- import java.util.Random;
- import java.util.Scanner;
- public class Punto05_TP4 {
- static Scanner ingreso= new Scanner(System.in);
- static Random aleatorio=new Random();
- public static void main(String[] args) {
- ejecutar();
- }
- public static void ejecutar() {
- SimpleLinkedList<Paciente> pacientes= new SimpleLinkedList<Paciente>();
- int opcion;
- do {
- opcion=menu();
- switch(opcion){
- case 1:
- cargaManual(pacientes);
- break;
- case 2:
- cargaAleatoria(pacientes);
- break;
- case 3:
- mostrarResultados(pacientes);
- break;
- }
- }while(opcion!=4);
- System.out.println("Fin del Programa");
- }
- public static int menu() {
- int opcion;
- System.out.println("Menu");
- System.out.println("1: Ingreso de pacientes manualmente");
- System.out.println("2: Generar pacientes aleatoriamente");
- System.out.println("3: Imprimir pacientes");
- System.out.println("4: Salir del programa");
- do{
- opcion= Helper.validarEntero(ingreso, "Ingrese una opcion 1,2,3 o 4:\n ");
- }while (opcion>4 ||opcion<=0);
- return opcion;
- }
- private static String[]algunServicio= {"Curacion", "Control", "Nebulizacion", "Vacunaciom"};
- private static String[] algunApellido= {"Alanis","Azurduy","Fernandez","Flores","Pizarro"};
- private static String[] algunNombre= {"Santiago","Victor","Nahuel","Daniel", "Matias"};
- private static Character[] algunSexo={'M','F'};
- private static String[] algunDomicilio= {"Huaico N° 1295","Perales N° 1234", "San Martin N° 1059", "Belgrano N° 1207"};
- public static String servicioPrestado(String mensaje) {
- int opcion;
- String respuesta="";
- do {
- opcion=Helper.enteroPositivo(ingreso, mensaje);
- switch (opcion){
- case 1:
- respuesta="Curacion";
- break;
- case 2:
- respuesta="Control";
- break;
- case 3:
- respuesta="Nebulizacion";
- break;
- case 4:
- respuesta= "Vacunacion";
- break;
- }
- if (opcion>=5) {
- System.out.println("Debe elegir 1, 2, 3 o 4");
- }
- }while (opcion>=5);
- return respuesta;
- }
- public static void cargaManual(SimpleLinkedList<Paciente> pacientes) {
- Calendar calendario=new GregorianCalendar();
- String respuesta="s";
- int edad,dia,mes,anio;
- Character sexo;
- while (respuesta.equalsIgnoreCase("s")) {
- String nombre=Helper.cadena("Ingrese su nombre:");
- String apellido=Helper.cadena("Ingrese su apellido:");
- do {
- edad=Helper.enteroPositivo(ingreso, "Ingrese su edad: ");
- }while(edad>100);
- do {
- sexo=Helper.validarCaracter(ingreso, "Ingrese su sexo M o F: " );
- sexo=sexo.toUpperCase(sexo);
- }while(sexo!='M'&&sexo!='F');
- String domicilio =Helper.cadena("Ingrese su domicilio calle y numero: ");
- String servicioPrestado=servicioPrestado("Seleccione servicio prestado: \n1: Curacion\n2: Control\n3: Nebulizacion\n4: Vacunacion");
- do {
- dia=Helper.enteroPositivo(ingreso, "Ingrese el dia: ");
- }while(dia>31);
- do {
- mes=Helper.enteroPositivo(ingreso, "Ingrese el mes en numero: ");
- }while(mes>12);
- do {
- anio=Helper.enteroPositivo(ingreso, "Ingrese el año: ");
- }while(anio<2010 || anio>2020);
- mes--;
- calendario.set(anio, mes, dia);
- Date fecha =calendario.getTime();
- Paciente lista=new Paciente(nombre, apellido, sexo, edad, domicilio, fecha, servicioPrestado);
- pacientes.agregarFinal(lista);
- System.out.println("Paciente \n"+lista);
- respuesta=Helper.respuestaSiNo(ingreso, "Desea ingresar otro paciente s/n: ");
- }
- System.out.println("Pacientes cargados");
- }
- public static void cargaAleatoria(SimpleLinkedList<Paciente> pacientes) {
- Calendar calendario=new GregorianCalendar();
- String respuesta="s";
- while (respuesta.equalsIgnoreCase("s")) {
- String nombre=algunNombre[aleatorio.nextInt(algunNombre.length)];
- String apellido=algunApellido[aleatorio.nextInt(algunApellido.length)];
- Integer edad=Helper.generaNumeroInt(100, 1);
- Character sexo=algunSexo[aleatorio.nextInt(algunSexo.length)];
- String domicilio =algunDomicilio[aleatorio.nextInt(algunDomicilio.length)];
- String servicioPrestado=algunServicio[aleatorio.nextInt(algunServicio.length)];
- int dia=Helper.generaNumeroInt(30, 1);
- int mes=Helper.generaNumeroInt(12, 1);
- int anio=2020;
- mes--;
- calendario.set(anio, mes, dia);
- Date fecha =calendario.getTime();
- Paciente lista=new Paciente(nombre, apellido, sexo, edad, domicilio, fecha, servicioPrestado);
- pacientes.agregarFinal(lista);
- System.out.println("Paciente generado \n"+lista);
- respuesta=Helper.respuestaSiNo(ingreso, "Desea generar otro paciente s/n: ");
- }
- System.out.println("Pacientes cargados");
- }
- public static void mostrarResultados(SimpleLinkedList<Paciente> pacientes) {
- int menorDe13=0;
- int curaciones=0;
- int controles=0;
- int nebulizaciones=0;
- int vacunaciones=0;
- int contador=0;
- System.out.println("Lista de Pacientes:");
- Iterator<Paciente> iterador=pacientes.iterator();
- while(iterador.hasNext()) {
- ++contador;
- Paciente paciente= iterador.next();
- System.out.println("Paciente "+contador+": "+paciente);
- if (paciente.getEdad()<13) {
- menorDe13++;
- }
- switch (paciente.getServicioPrestado()) {
- case "Curacion":
- curaciones++;
- break;
- case "Control":
- controles++;
- break;
- case "Nebulizacion":
- nebulizaciones++;
- break;
- case "Vacunacion":
- vacunaciones++;
- break;
- }
- }
- System.out.println("Cantidad de niños menores de 13: "+ menorDe13);
- System.out.println("Cantidad de Curaciones: "+curaciones);
- System.out.println("Cantidad de Controles: "+controles);
- if (nebulizaciones>vacunaciones) {
- System.out.println("La cantidad de nebulizaciones supera a la cantidad de vacunaciones\n"+"Nebulizaciones: "+nebulizaciones+" Vacunaciones: "+vacunaciones);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement