Advertisement
RAUL-SUAREZ

tp4-punto3-2

Nov 1st, 2021
3,721
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.*;
  2. public class Helper {
  3.     //validar numeros
  4.     public static int validarNumero(Scanner valorIngresado, String mensaje) {
  5.         int numero;
  6.         String linea;
  7.         while (true) {
  8.             try {
  9.                 System.out.println(mensaje);
  10.                 linea = valorIngresado.nextLine();
  11.                 numero = Integer.parseInt(linea);
  12.                 break;
  13.             } catch (Exception e) {
  14.                 System.out.println("''ERROR..! Ingrese un Numero Positivo''");
  15.             }
  16.         }
  17.         return numero;
  18.     }
  19.     //validar opcion random o manual
  20.     public static int elegirOpcion(Scanner opcion , String mensaje){
  21.         int numero;
  22.         String linea;
  23.         while (true) {
  24.             try {
  25.                 System.out.println(mensaje);
  26.                 linea = opcion.nextLine();
  27.                 numero = Integer.parseInt(linea);
  28.                 while(!(numero<=2 && numero>=1)){
  29.                     System.out.println("Opcion Incorrecta");
  30.                     System.out.println(mensaje);
  31.                     linea = opcion.nextLine();
  32.                     numero = Integer.parseInt(linea);
  33.                 }
  34.                 break;
  35.             } catch (Exception e) {
  36.                 System.out.println("''ERROR..! Ingrese un numero''");
  37.             }
  38.         }
  39.         return numero;
  40.     }
  41.     //validar que se ingrese solamente letras primera parte
  42.     public static String cargarLetra(Scanner entrada,String mensaje){
  43.         System.out.println(mensaje);
  44.         String linea=entrada.nextLine();
  45.         while(validarLetras(linea)){
  46.             System.out.println("''ERROR'' No Ingresar Numeros");
  47.             System.out.println(mensaje);
  48.             linea=entrada.nextLine();
  49.         }    
  50.         return linea;
  51.     }
  52.     //validar que se ingrese solamente letras segunda parte
  53.     public static boolean validarLetras(String linea) {
  54.         for (int x = 0; x < linea.length(); x++) {
  55.             char c = linea.charAt(x);
  56.             if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == ' ')) {
  57.                 return true;
  58.             }
  59.         }
  60.         return false;
  61.     }
  62.  
  63.     //Genera caracter random
  64.     public static String caracterRandom() {
  65.         Random random = new Random();
  66.         char caracterRandom = (char)(random.nextInt(26) + 'a');
  67.         System.out.println("Caracter generado: "+ caracterRandom);
  68.         String caracter = String.valueOf(caracterRandom);
  69.         return caracter;
  70.     }
  71.  
  72.     //Genera Nombre Random
  73.     public static String nombreRandom(){
  74.         int random;
  75.         String [] nombre ={"Fernanda","Lorena ","Martín ","Sara","Pedro","Gabriel","Gerardo","Lis","Catriel","Camila"};
  76.         random = (int) (Math.random() * nombre.length);
  77.         return nombre[random];
  78.     }
  79.  
  80.     //Cargar correo random
  81.     public static String correoRandom(){
  82.         int random;
  83.         String [] correo ={"Marcopolo@gmail.com","grein123@hotmail.com ","dr-bles@hotmail.com ","darkBoss-123@gmal.com",
  84.         "gener@gmail.com","runu-wuw@hotmail.com","bro10@gmail.com","Replay@hotmail.com","dowH@gmail.com.es","shawer@yahoo.com"};
  85.         random = (int) (Math.random() * correo.length);
  86.         return correo[random];
  87.     }
  88.    
  89.     //Generar correo random 2
  90.     public static void correoRandom2(ArrayList<String> correos,Scanner entrada){
  91.         int random;
  92.         String opcion ="s";
  93.         String [] correo ={"Marcopolo@gmail.com","grein123@hotmail.com ","dr-bles@hotmail.com ","darkBoss-123@gmal.com",
  94.             "gener@gmail.com","runu-wuw@hotmail.com","bro10@gmail.com","Replay@hotmail.com","dowH@gmail.com.es","shawer@yahoo.com"};
  95.         while (opcion.equalsIgnoreCase("s")){
  96.             random = (int) (Math.random() * correo.length);
  97.             System.out.println("¿agregar otro correo?");
  98.             opcion = entrada.nextLine();
  99.             correos.add(correo[random]);
  100.  
  101.         }
  102.     }
  103.     //sin uso aun
  104.     public static void cargarMatriz(int [][] x,Scanner entrada){
  105.         for (int i=0; i<3;i++){
  106.             for (int j=0;j<3;j++){
  107.                 System.out.println("ingrese valores de matriz");
  108.                 x[i][j]= Integer.parseInt(entrada.next());
  109.  
  110.             }
  111.  
  112.         }      
  113.     }
  114.     //sin uso aun
  115.     public static void mostrarMatriz(int[][]x){
  116.         for (int i=0; i<x.length;i++){
  117.             for (int j=0;j<x.length;j++){
  118.                 System.out.print(x[i][j]+" ");
  119.  
  120.             }
  121.             System.out.println("");  
  122.         }
  123.     }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement