Advertisement
MOISES_QUISPE_ROJAS

Estructura Datos 2021 - TP01 P05

Sep 15th, 2021
1,295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 12.39 KB | None | 0 0
  1. /* Estructura de Datos - Facultad de Ingenieria - Universidad Nacional de Jujuy
  2.  *
  3.  * @Autor: Equipo 4.1
  4.  */
  5. /*      @integrantes:                  |    @Carrera:             |   @LU:
  6.                                        |                          |
  7.   Flores ,Cesar Ismael                 | Lic. en Sistemas         | 1782
  8.   Llampa, Ariel Angel Gabriel          | Ing. Informatica         | 8445
  9.   Machaca, Rodrigo Agustin             | Ing. Informatica         | 8512
  10.   Perez, Emanuel Ismael                | Ing. Informatica         | 8393
  11.   Quispe Rojas, Moises Esteban Nicolas | Ing. Informatica         | 7286
  12.  
  13. Escribir un programa que permita ingresar la información de muchas personas de acuerdo a la
  14. implementación del caso ejemplo c); luego el usuario podrá indicar un rango de años de nacimiento en
  15. particular y el programa deberá mostrar las personas cuyos años de nacimiento se encuentren dentro del
  16. rango especificado.
  17.  
  18. Indicaciones:
  19. Este ejercicio necesita del objeto scanner para ingresar datos por la consola o teclado, se espera que el
  20. código controle los problemas que normalmente ocurren al operar con la consola o teclado.
  21. Se espera una correcta modularización entre el código que realiza el ingreso y validación de los datos
  22. respecto del código que hace lo que se solicita en el ejercicio.
  23. El ejercicio debe implementar un mecanismo para seleccionar el ingreso de valores por consola o
  24. generados aleatoriamente.
  25.  
  26. */
  27.  
  28. package Array;
  29.  
  30. import java.text.ParseException;
  31. import java.text.SimpleDateFormat;
  32. import java.util.ArrayList;
  33. import java.util.Date;
  34. import java.util.regex.Matcher;
  35. import java.util.regex.Pattern;
  36.  
  37. public class ED_E5 {
  38.     private ArrayList<Persona> persona = new ArrayList<>();
  39.     private static final SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
  40.     private static final Date invalidDate = new Date(0);
  41.    
  42.     public static void main(String[] args) {
  43.         (new ED_E5()).open();
  44.     }
  45.    
  46.     public void open(){
  47.         char option;
  48.         do{
  49.             System.out.println("Registro de Personas");
  50.             System.out.println("(a) Registro Manual");
  51.             System.out.println("(b) Registro Automatico");              
  52.             System.out.print("Opcion: ");
  53.             option=Helper.getChar();
  54.         }while(run(option));
  55.         info();
  56.     }
  57.    
  58.     public void info(){
  59.         Date minDate,maxDate;
  60.         System.out.println("Se buscara personas dentro de un rango de fechas");
  61.         System.out.print("Desde: ");
  62.         minDate=Helper.getDate();      
  63.         do{
  64.             System.out.print("Hasta: ");
  65.             maxDate=Helper.getDate();
  66.         }while(validateMaximum(minDate,maxDate));
  67.         System.out.println("Las siguientes persones se encuentran entre "+sdf.format(minDate)+" y "+sdf.format(minDate));
  68.         for (int i=0; i<getPersona().size();i++) {
  69.             // Se evalua en los extremos
  70.             if(getPersona().get(i).getFechaNacimiento().equals(minDate)||getPersona().get(i).getFechaNacimiento().equals(maxDate)){
  71.                 System.out.println(getPersona().get(i));
  72.             }
  73.             // Se evalua en fechas de por medio
  74.             if((getPersona().get(i).getFechaNacimiento().after(minDate))&((getPersona().get(i).getFechaNacimiento().before(maxDate)))){
  75.                 System.out.println(getPersona().get(i));
  76.             }
  77.         }
  78.     }
  79.      
  80.     public boolean validateMaximum(Date minDate,Date maxDate){
  81.         if(minDate.equals(maxDate)){
  82.             System.out.println("Debe ingresar una fecha distinta a la ingresada anteriormente");
  83.             return true;
  84.         }
  85.         if(minDate.after(maxDate)){
  86.             System.out.println("Debe ingresar una fecha mayor a la ingresada anteriormente");
  87.             return true;
  88.         }else{
  89.             return false;
  90.         }
  91.     }    
  92.  
  93.     public void registerManual(){
  94.         String apellido,nombre,correo;
  95.         char resp;
  96.         int documento,numeroCelular;        
  97.         Date fechaNacimiento;
  98.         do{
  99.             System.out.print("Ingrese Apellido: ");
  100.             apellido= Helper.getString();
  101.             System.out.print("Ingrese Nombre: ");
  102.             nombre=Helper.getString();  
  103.             do{
  104.                 System.out.print("Ingrese DNI: ");
  105.                 documento=Helper.getIntegerPositive();
  106.             }while(validateDni(documento));
  107.             System.out.print("Ingrese Fecha de Nacimiento(DD/MM/YYYY): ");
  108.             fechaNacimiento=Helper.getDate();  
  109.             do{
  110.                 System.out.print("Ingrese mail: ");
  111.                 correo=Helper.getString();
  112.             }while(validateMail(correo));
  113.             do{
  114.                 System.out.print("Ingrese Num. Celular (15-...): ");
  115.                 numeroCelular=Helper.getIntegerPositive();
  116.             }while(validateCel(Integer.toString(numeroCelular)));
  117.             getPersona().add(new Persona(apellido, nombre, documento, fechaNacimiento, correo, numeroCelular));
  118.             do{
  119.                 System.out.print("Desea cargar otra persona (S/N): ");
  120.                 resp = Helper.getChar();
  121.             }while(validateChar(resp));
  122.         }while((resp=='s')|(resp=='S'));
  123.         System.out.println("Se cargaron las siguientes personas: ");
  124.         System.out.println(getPersona());
  125.     }
  126.    
  127.     public boolean validateDni(int documento){
  128.         if((documento>=100000)&(documento<=99999999)){
  129.             return false;
  130.         }else{
  131.             System.out.println("Error...");
  132.             System.out.println("El DNI debe estar comprendido entre 6 y 8 cifras ");
  133.             return true;
  134.         }
  135.     }
  136.    
  137.     public boolean validateChar(char resp){
  138.         switch (resp){
  139.             case 's','S': return false;
  140.             case 'n','N': return false;
  141.             default:{
  142.                 System.out.println("Debe ingresar (S/N)");
  143.                 return true;
  144.             }  
  145.         }
  146.     }
  147.  
  148.     public boolean validateCel(String numeroCelular){
  149.         Pattern pattern = Pattern.compile("^(15)[0-9]{7}$");
  150.          Matcher mather = pattern.matcher(numeroCelular);
  151.          if (mather.find()) {
  152.             return false;
  153.         } else {
  154.             System.out.println("Error...");
  155.             System.out.println("El Num. de Celular debe estar comprendido entre 9 cifras");
  156.              System.out.println("EJ: 15 4040314");
  157.             return true;
  158.         }
  159.     }
  160.    
  161.     public boolean validateMail(String correo){
  162.         Pattern pattern = Pattern.compile("^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$");
  163.         Matcher mather = pattern.matcher(correo);
  164.         if (mather.find()) {
  165.             return false;
  166.         } else {
  167.             System.out.println("Error...");
  168.             System.out.println("El mail ingresado es incorrecto");
  169.             return true;
  170.         }
  171.     }
  172.    
  173.     public boolean run(char option){
  174.         switch(option){
  175.             case 'a','A':
  176.                 registerManual();
  177.                 return false;
  178.             case 'b','B':
  179.                 registerAutomatic();
  180.                 return false;
  181.                 default:{
  182.                     System.out.println("Error...");
  183.                     System.out.println("Intentelo de nuevo");
  184.                     return true;
  185.                 }
  186.         }
  187.     }
  188.    
  189.     public void registerAutomatic(){
  190.         String apellido,nombre,correo;
  191.         int documento,numeroCelular,i=0,randomCreate=Helper.random.nextInt(20)+1;
  192.         Date fechaNacimiento;
  193.         do{
  194.             apellido= someSurnames[Helper.random.nextInt(someSurnames.length)];
  195.             nombre=someNames[Helper.random.nextInt(someNames.length)];      
  196.             documento=someDNI[Helper.random.nextInt(someDNI.length)];      
  197.             fechaNacimiento=someDate[Helper.random.nextInt(someDate.length)];  
  198.             correo=someMail[Helper.random.nextInt(someMail.length)];
  199.             numeroCelular=someNumber[Helper.random.nextInt(someNumber.length)];
  200.             getPersona().add(new Persona(apellido, nombre, documento, fechaNacimiento, correo, numeroCelular));
  201.             i++;
  202.         }while(i<randomCreate);
  203.         System.out.println("Se generaron las siguientes personas: ");
  204.         System.out.println(getPersona());
  205.     }
  206.    
  207.     public Date fromString( String spec ) {
  208.         try {
  209.             return sdf.parse( spec );
  210.         } catch( ParseException dfe ) {
  211.             return invalidDate;
  212.         }
  213.     }
  214.    
  215.     private Date[] someDate= {
  216.         fromString("01/01/2020"),
  217.         fromString("29/09/1996"),
  218.         fromString("01/02/1998"),
  219.         fromString("12/12/2021"),
  220.         fromString("19/07/1997"),
  221.         fromString("15/11/2001"),
  222.         fromString("11/09/2005"),
  223.         fromString("30/01/2020"),
  224.         fromString("01/12/1996"),
  225.         fromString("15/07/1998"),
  226.         fromString("21/05/2010"),
  227.         fromString("23/08/1997"),
  228.         fromString("05/05/1999"),
  229.         fromString("20/12/1986"),
  230.         fromString("19/09/1977"),
  231.         fromString("21/06/1978"),
  232.         fromString("12/05/1995"),
  233.         fromString("11/09/2013"),
  234.         fromString("13/07/1997"),
  235.         fromString("12/08/2001")      
  236.     };
  237.    
  238.     private int[] someNumber={
  239.         154464257,
  240.         155665587,
  241.         154885698,
  242.         154668844,
  243.         154040314,
  244.         155449913,
  245.         154669977,
  246.         153369745,
  247.         154885521,
  248.         154448511,
  249.         155223348,
  250.         155894563,
  251.         154885913,
  252.         154448853,
  253.         155666313,
  254.         154854975,
  255.         154444684,
  256.         154552689,
  257.         154995613,
  258.         155336684,
  259.         154897982,
  260.         154789681,
  261.         155567321,
  262.         155687953,
  263.         154321894
  264.     };
  265.    
  266.     private String[] someMail={
  267.         "pavohottautto-8929@gmail.com",
  268.         "nojofapouho-2479@hotmail.com",
  269.         "kibredayeppe-2034@gmail.com",
  270.         "loucraseuppaddo-5744@hotmail.com",
  271.         "colorekeissu-4864@gmail.com",
  272.         "musoiheceha-7278@hotmmail.com",
  273.         "groquaudaquoiva-2582@gmail.com",
  274.         "creittovapoihe-9470@gmail.com",
  275.         "luvuracrata-3715@gmail.com",
  276.         "xegugusouppa-9677@hotmail.com",
  277.         "jillunegroipra-9474@gmail.com",
  278.         "duprizeiquajo-2695@hotmail.com",
  279.         "tureipeddoili-1853@hotmail.com",
  280.         "wobaxehipei-3003@hotmail.com",
  281.         "woyetrepreule-2878@gmail.com",
  282.         "pekegeyenne-3980@hotmail.com",
  283.         "tefrelemage-7137@hotmail.com",
  284.         "jeddazeiluboi-4042@gmail.com",
  285.         "pribigrissubu-2501@gmail.com",
  286.         "zimeprannuwu-8622@hotmail.com",
  287.         "douppazoicrebrei-3605@hotmail.com",  
  288.         "xoqueuprurutra-2509@hotmail.com",
  289.         "giyoiddugrelli-8055@gmail.com",
  290.         "taufreuveyefra-5445@hotmail.com",
  291.         "muddoipretrodau-5721@hotmail.com"
  292.     };
  293.    
  294.     private int[] someDNI={
  295.         39231923,
  296.         27616941,
  297.         8205546,
  298.         36941731,
  299.         38205546,
  300.         36048402,
  301.         43527322,
  302.         27727017,
  303.         40015131,
  304.         40175708,
  305.         40898441,
  306.         39989859,
  307.         33690033,
  308.         34346583,
  309.         37460276,
  310.         40175708,
  311.         38655652,
  312.         39738478,
  313.         40132830,
  314.         27110561,
  315.         34065779,
  316.         39930449,
  317.         40898405
  318.     };
  319.    
  320.     private String[] someSurnames={
  321.         "González",
  322.         "Gómez",
  323.         "Díaz",
  324.         "Chavez",
  325.         "Bermudez",
  326.         "Sanchez",
  327.         "Mendoza",
  328.         "Blazquez",
  329.         "Antunez",
  330.         "Muñoz",
  331.         "Ibañez",
  332.         "Hernandez",
  333.         "Valdez",
  334.         "Yañez",
  335.         "Rojas",
  336.         "Tellez",
  337.         "Ruiz",
  338.         "Paez",
  339.         "Ortiz",
  340.         "Ordoñez"
  341.     };
  342.    
  343.     private String[] someNames={
  344.         "Álan",
  345.         "Jacinto",
  346.         "Martinez",
  347.         "Alicia",
  348.         "Jesús",
  349.         "Mirta",
  350.         "Andrea",
  351.         "Josefina",
  352.         "Mónica",
  353.         "Andrés",
  354.         "Juan",
  355.         "Nicolás",
  356.         "Antonia",
  357.         "Juana",
  358.         "Noé",
  359.         "Antonio",
  360.         "Juano",
  361.         "Noelia",
  362.         "Azul",
  363.         "Julia",
  364.         "Paula",
  365.         "Bartolomé",
  366.         "Julián",
  367.         "Pomponio",
  368.         "Belén"   
  369.     };
  370.  
  371.     public ArrayList<Persona> getPersona() {
  372.         return persona;
  373.     }
  374.  
  375.     public void setPersona(ArrayList<Persona> persona) {
  376.         this.persona = persona;
  377.     }
  378.    
  379. }
  380.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement