Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Scanner;
- public class Tp1Ej5{
- public static void main(String[] args) {
- ArrayList<Persona> listaDePersonas = new ArrayList<Persona>();
- Persona datos;
- Scanner entrada = new Scanner(System.in);
- String apellido,nombre,correo;
- int documento,numeroClular,opcion;
- int fecha [] ;
- String continuar = "s";
- while(continuar.equalsIgnoreCase("s")){
- opcion= Modulo.elegirOpcion(entrada,"'opcion' \n1-Manual \n2-Random");
- if (opcion==1){
- apellido = cargarLetra(entrada,"Ingrese Apellido");
- nombre = cargarLetra(entrada,"Ingrese Nombre" );
- documento = cargarDocumento();
- cargarFecha(fecha = new int[3],entrada);
- correo = cargarCorreo(entrada);
- numeroClular = cargarNumeroCelular();
- datos = new Persona(apellido, nombre, documento, fecha, correo, numeroClular);
- listaDePersonas.add(datos);
- }
- else{
- apellido = apellidoRandom();
- nombre = nombreRandom();
- documento =(int) (Math.random() * 100000000);
- cargarFechaRandom(fecha = new int[3]);
- correo = correoRandom();
- numeroClular = (int) (Math.random() * 10000000);
- datos = new Persona(apellido, nombre, documento, fecha, correo, numeroClular);
- listaDePersonas.add(datos);
- }
- continuar = valiadarOpcion(entrada);
- }
- for (Persona PeronasRegistradas : listaDePersonas){
- System.out.println(PeronasRegistradas);
- }
- rangoAños(listaDePersonas);
- }
- private static String valiadarOpcion(Scanner entrada){
- System.out.println("¿Desea Continuar? [s/n]");
- String opcion = entrada.nextLine();
- while(!(opcion.equalsIgnoreCase("s")||opcion.equalsIgnoreCase("n"))){
- System.out.println("Opcion Incorrecta");
- System.out.println("¿Desea Continuar? [s/n]");
- opcion = entrada.nextLine();
- }
- return opcion;
- }
- private static String cargarLetra(Scanner entrada,String mensaje){
- System.out.println(mensaje);
- String linea=entrada.nextLine();
- while(validarLetras(linea)){
- System.out.println("''ERROR'' No Ingresar Numeros");
- System.out.println(mensaje);
- linea=entrada.nextLine();
- }
- return linea;
- }
- public static boolean validarLetras(String linea) {
- for (int x = 0; x < linea.length(); x++) {
- char c = linea.charAt(x);
- // Si no está entre a y z, ni entre A y Z, ni es un espacio
- if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == ' ')) {
- return true;
- }
- }
- return false;
- }
- public static int cargarDocumento(){
- Scanner entrada = new Scanner(System.in);
- int numeroDocumento= Modulo.validarNumero(entrada, "Ingrese Numero de Documento: xxxxxxxx");
- while(!(validarDocumento(numeroDocumento))){
- System.out.println("el documento debe tener 8 cifras");
- numeroDocumento= Modulo.validarNumero(entrada, "Ingrese Numero de Documento: xxxxxxxx");
- }
- return numeroDocumento;
- }
- public static boolean validarDocumento(int numeroDocumento){
- String cifras = Integer.toString(numeroDocumento);
- if (cifras.length()==8){
- return true;
- }
- else{
- return false;
- }
- }
- public static void cargarFecha(int [] fecha, Scanner entrada){
- int dia,mes,año;
- dia = Modulo.validarNumero(entrada, "Ingresar Dia [1/31]");
- mes = Modulo.validarNumero(entrada, "Ingresar Mes: [1/12]");
- año = Modulo.validarNumero(entrada, "Ingresar Año: [1930/2021]");
- while(!(validarFecha(dia, mes, año))){
- System.out.println("Ingrese los Datos Nuevamente");
- dia = Modulo.validarNumero(entrada, "Ingresar Dia [1/31]");
- mes = Modulo.validarNumero(entrada, "Ingresar Mes: [1/12]");
- año = Modulo.validarNumero(entrada, "Ingresar Año: [1930/2021]");
- }
- fecha[0] = dia;
- fecha[1] = mes;
- fecha[2] = año;
- }
- public static boolean validarFecha(int dia ,int mes,int año){
- String lineaDia,lineaMes,lineaAño;
- boolean validar = true;
- lineaDia = Integer.toString(dia);
- lineaMes = Integer.toString(mes);
- lineaAño = Integer.toString(año);
- if(lineaDia.length()<=2 && dia>=1 && dia<=31){
- if(lineaMes.length()<=2 && mes>=1 && mes<=12){
- if(lineaAño.length()==4 && año>=1930 && año<=2021){
- validar = true;
- }
- else{
- System.out.println("El Año ingresado es incorrecto");
- validar = false;
- }
- }
- else{
- System.out.println("El Mes ingresado es incorrecto");
- validar = false;
- }
- }
- else{
- System.out.println("El Dia ingresado es incorrecto");
- validar = false;
- }
- return validar;
- }
- public static String cargarCorreo(Scanner entrada) {
- System.out.println("ingresar correo");
- String correo = entrada.nextLine();
- while (!(correo.contains("@") && correo.contains("."))){
- System.out.println("ingresar correo con @ y .");
- correo = entrada.nextLine();
- }
- return correo;
- }
- public static int cargarNumeroCelular() {
- Scanner entrada = new Scanner(System.in);
- int numeroClular = Modulo.validarNumero(entrada, "Ingrese Numero de Celular sin (+54)388");
- while (!(validarNumeroCelular(numeroClular))){
- System.out.println("''ERROR''");
- numeroClular = Modulo.validarNumero(entrada, "Ingrese Numero de Celular sin (+54)388");
- }
- return numeroClular;
- }
- public static boolean validarNumeroCelular(int numeroClular) {
- String numero = Integer.toString(numeroClular);
- if (numero.length()==7){
- return true;
- }
- else{
- return false;
- }
- }
- public static void rangoAños(ArrayList<Persona> listaDePersonas) {
- Scanner entrada = new Scanner(System.in);
- int desde,hasta;
- int[] año;
- System.out.println("Rango de Edad[1930/2021]");
- desde = Modulo.validarNumero(entrada,"Mostrar rango de edad desde");
- hasta = Modulo.validarNumero(entrada,"hasta");
- while (!(validarRango(desde,hasta))){
- System.out.println("''ERROR'' Ingrese los Datos Nuevamente");
- desde = Modulo.validarNumero(entrada,"Mostrar rango de edad desde");
- hasta = Modulo.validarNumero(entrada,"hasta");
- }
- System.out.println("Mostrando Lista de Personas["+desde+","+hasta+"]");
- for (int i=0;i<listaDePersonas.size();i++){
- año = listaDePersonas.get(i).getFecha(2);
- if (año[2]>desde && año[2]<hasta){
- System.out.println(listaDePersonas.get(i));
- }
- }
- }
- public static boolean validarRango(int desde, int hasta) {
- String lineaDesde,lineaHasta;
- lineaDesde = Integer.toString(desde);
- lineaHasta = Integer.toString(hasta);
- if (lineaDesde.length()==4 && desde<hasta && desde>=1930 && desde<=2021){
- if (lineaHasta.length()==4 && hasta>=1930 && hasta<=2021){
- return true;
- }
- else{
- return false;
- }
- }
- else{
- return false;
- }
- }
- public static String apellidoRandom(){
- int random;
- String [] apellido ={"Fernández","López ","Martínez ","Sánchez","Pérez","Gómez","Serapio","Gutierrez","Zerpa","Soruco"};
- random = (int) (Math.random() * apellido.length);
- return apellido[random];
- }
- public static String nombreRandom(){
- int random;
- String [] nombre ={"Fernanda","Lorena ","Martín ","Sara","Pedro","Gabriel","Gerardo","Lis","Catriel","Camila"};
- random = (int) (Math.random() * nombre.length);
- return nombre[random];
- }
- public static void cargarFechaRandom(int [] fecha){
- int dia,mes,año;
- dia =(int) (Math.random()*30+1);
- mes = (int) (Math.random()*11+1);
- año = (int) (Math.random()*2021);
- while(!(validarFechaRandom(dia, mes, año))){
- dia =(int) (Math.random()*30+1);
- mes = (int) (Math.random()*11+1);
- año = (int) (Math.random()*2021);
- }
- fecha[0] = dia;
- fecha[1] = mes;
- fecha[2] = año;
- }
- public static boolean validarFechaRandom(int dia ,int mes,int año){
- String lineaDia,lineaMes,lineaAño;
- boolean validar = true;
- lineaDia = Integer.toString(dia);
- lineaMes = Integer.toString(mes);
- lineaAño = Integer.toString(año);
- if(lineaDia.length()<=2 && dia>=1 && dia<=31){
- if(lineaMes.length()<=2 && mes>=1 && mes<=12){
- if(lineaAño.length()==4 && año>=1930 && año<=2021){
- validar = true;
- }
- else{
- validar = false;
- }
- }
- else{
- validar = false;
- }
- }
- else{
- validar = false;
- }
- return validar;
- }
- public static String correoRandom(){
- int random;
- String [] correo ={"Marcopolo@gmail.com","grein123@hotmail.com ","dr-bles@hotmail.com ","darkBoss-123@gmal.com",
- "gener@gmail.com","runu-wuw@hotmail.com","bro10@gmail.com","Replay@hotmail.com","dowH@gmail.com.es","shawer@yahoo.com"};
- random = (int) (Math.random() * correo.length);
- return correo[random];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement