Advertisement
ismael20

Ejercicio_5

Oct 25th, 2021 (edited)
1,295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.62 KB | None | 0 0
  1. package TP4;
  2.  
  3. import java.util.regex.Matcher;
  4. import java.util.regex.Pattern;
  5.  
  6. public class Ejercicio_5 {
  7.    
  8.       private ILinkedList<Schedule> Agends;
  9.    
  10.       public void Run() {
  11.          
  12.           Agends = new SimpleLinkedList<>();
  13.          
  14.           getData();
  15.           System.out.println("Los datos son:  " + Agends.toString());
  16.          
  17.       }
  18.    
  19.    
  20.     private void getData() {
  21.         Integer Option;
  22.         while(true) {
  23.             System.out.println(
  24.                 "\n Trabajo Practico N°4 - Ejercicio 4  \n" +
  25.                         "\nOpciones" +
  26.                         "\n 1. Ingresa valores por consola" +
  27.                         "\n 2. Generar valores aleatorios" 
  28.             );
  29.             Option = Helper.getInteger();
  30.            
  31.             switch (Option) {
  32.             case 1:
  33.                 //consoleInput();
  34.                 return;
  35.             case 2:
  36.                 //consoleGenerate();
  37.                 return;
  38.             }
  39.         }
  40.     }
  41.        
  42.     private void consoleInput() {
  43.         String Full_Name = "";
  44.         String Work;
  45.         Integer Telephone;
  46.         String Mail;
  47.         int position;
  48.         char resp;
  49.         System.out.println("\n Ingrese los datos a agendar");
  50.         do {
  51.  
  52.             do {
  53.                 System.out.println("Ingrese Nombre Completo: ");
  54.                 Full_Name = Helper.getString();
  55.             } while (Validate_FullName(Full_Name));
  56.  
  57.             System.out.println("Ingrese Trabajo o Empresa: ");
  58.             Work = Helper.getString();
  59.  
  60.             do {
  61.                 System.out.println("Ingrese numero de celular: ");
  62.                 Telephone = Helper.getIntegerPositive();
  63.  
  64.             } while (ValidateCel(Integer.toString(Telephone)));
  65.  
  66.             do {
  67.                 System.out.println("Ingrese correo: ");
  68.                 Mail = Helper.getString();
  69.             } while (ValidateMail(Mail));
  70.  
  71.             while (true) {
  72.                 System.out.println("Donde agrega el producto [1. Adelante,  2. Final]");
  73.                 position = Helper.getInteger();
  74.                 if (position == 1) {
  75.                     Agends.addFirst(new Schedule(Full_Name, Work, Telephone, Mail));
  76.                     break;
  77.                 } else {
  78.                     if (position == 2) {
  79.                         Agends.addLast(new Schedule(Full_Name, Work, Telephone, Mail));
  80.                         break;
  81.                     }
  82.                 }
  83.             }
  84.             do {
  85.                 System.out.println("Desea cargar mas Datos (S/N)");
  86.                 resp = Helper.getChar();
  87.             } while (validateChar(resp));
  88.  
  89.         } while (resp == 'S');
  90.  
  91.     }
  92.    
  93.     private void radomGenerate() {
  94.         String Full_Name = "";
  95.         String Work;
  96.         Integer Telephone;
  97.         String Mail;
  98.         int position;
  99.        
  100.         for (int count=Helper.random.nextInt(20)+1 ; count > 0 ; -- count) {
  101.             Full_Name= FullName[Helper.random.nextInt(FullName.length)];
  102.             Work= work[Helper.random.nextInt(work.length)];
  103.             Telephone= Cel[Helper.random.nextInt(Cel.length)];
  104.             Mail= mail[Helper.random.nextInt(mail.length)];
  105.             position= Helper.random.nextInt(2) + 1;
  106.             if(position == 1) {
  107.                 Agends.addFirst(new Schedule(Full_Name, Work, Telephone, Mail));
  108.             } else {
  109.                 if(position == 2) {
  110.                     Agends.addLast(new Schedule(Full_Name, Work, Telephone, Mail));
  111.                 }
  112.             }
  113.            
  114.         }
  115.        
  116.        
  117.        
  118.     }
  119.    
  120.     private boolean Validate_FullName(String Full_Name) {
  121.         Pattern pattern = Pattern.compile("[^([A-Z]{1}[a-z]+[ ]){1,3}$");
  122.         Matcher mather = pattern.matcher(Full_Name);
  123.         if(mather.find()) {
  124.             return false;
  125.         } else {
  126.             System.out.println("Error...");
  127.             System.out.println("El nombre ingresado es incorrecto");
  128.             return true;
  129.         }
  130.                    
  131.     }
  132.     public boolean ValidateCel(String Telephone){
  133.         Pattern pattern = Pattern.compile("^(15)[0-9]{10}$");
  134.          Matcher mather = pattern.matcher(Telephone);
  135.          if (mather.find()) {
  136.              return false;
  137.         } else {
  138.             System.out.println("Error...");
  139.             System.out.println("El Num. de Celular debe estar comprendido entre 12 cifras");
  140.              System.out.println("EJ: 15 4040314");
  141.             return true;
  142.         }
  143.     }
  144.     public boolean ValidateMail(String Mail){
  145.         Pattern pattern = Pattern.compile("^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$");
  146.         Matcher mather = pattern.matcher(Mail);
  147.         if (mather.find()) {
  148.             return false;
  149.         } else {
  150.             System.out.println("Error...");
  151.             System.out.println("El mail ingresado es incorrecto");
  152.             return true;
  153.         }
  154.     }
  155.     public boolean validateChar(char resp){
  156.         switch (resp){
  157.             case 's': return false;
  158.             case 'S': return false;
  159.             case 'n': return false;
  160.             case 'N': return false;
  161.             default:{
  162.                 System.out.println("Debe ingresar (S/N)");
  163.                 return true;
  164.             }  
  165.         }
  166.     }
  167.    
  168.    
  169.     static String [] FullName = new String [] {
  170.             "Ana Mamani",
  171.             "Luciana Lopez",
  172.             "Mariana Flores",
  173.             "Gustavo Quispe",
  174.             "Luciano Herrera",
  175.             "Enzo Lopez",
  176.             "Mariano Gaspar",
  177.             "Hugo Albornoz",
  178.             "Celeste Aban",
  179.             "Emilio Gareca"
  180.            
  181.     };
  182.     static String [] work = new String [] {
  183.             "Contador",
  184.             "Arquitecto",
  185.             "Abogado",
  186.             "Ingeniero",
  187.             "Medico",
  188.             "Enfermero",
  189.     };
  190.    
  191.     static String [] mail = new String [] {
  192.             "nojofapouho-2479@hotmail.com",
  193.             "kibredayeppe-2034@gmail.com",
  194.             "loucraseuppaddo-5744@hotmail.com",
  195.             "colorekeissu-4864@gmail.com",
  196.             "jillunegroipra-9474@gmail.com",
  197.             "duprizeiquajo-2695@hotmail.com",
  198.             "tureipeddoili-1853@hotmail.com",
  199.             "wobaxehipei-3003@hotmail.com",
  200.             "woyetrepreule-2878@gmail.com",
  201.             "pekegeyenne-3980@hotmail.com",
  202.     };
  203.    
  204.     static int [] Cel = new int [] {
  205.             154464257,
  206.             155665587,
  207.             154885698,
  208.             154668844,
  209.             154040314,
  210.             154448853,
  211.             155666313,
  212.             154854975,
  213.             154444684,
  214.             154552689,
  215.     };
  216.            
  217.  
  218. }
  219.  
  220.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement