SHOW:
|
|
- or go back to the newest paste.
| 1 | import java.util.ArrayList; | |
| 2 | import java.util.Scanner; | |
| 3 | ||
| 4 | public class Tp1Ej5{
| |
| 5 | public static void main(String[] args) {
| |
| 6 | ArrayList<Persona> listaDePersonas = new ArrayList<Persona>(); | |
| 7 | Persona datos; | |
| 8 | Scanner entrada = new Scanner(System.in); | |
| 9 | String apellido,nombre,correo; | |
| 10 | int documento,numeroClular,opcion; | |
| 11 | int fecha [] ; | |
| 12 | String continuar = "s"; | |
| 13 | ||
| 14 | while(continuar.equalsIgnoreCase("s")){
| |
| 15 | opcion= Modulo.elegirOpcion(entrada,"'opcion' \n1-Manual \n2-Random"); | |
| 16 | if (opcion==1){
| |
| 17 | apellido = cargarLetra(entrada,"Ingrese Apellido"); | |
| 18 | nombre = cargarLetra(entrada,"Ingrese Nombre" ); | |
| 19 | documento = cargarDocumento(); | |
| 20 | cargarFecha(fecha = new int[3],entrada); | |
| 21 | correo = cargarCorreo(entrada); | |
| 22 | numeroClular = cargarNumeroCelular(); | |
| 23 | datos = new Persona(apellido, nombre, documento, fecha, correo, numeroClular); | |
| 24 | listaDePersonas.add(datos); | |
| 25 | } | |
| 26 | else{
| |
| 27 | apellido = apellidoRandom(); | |
| 28 | nombre = nombreRandom(); | |
| 29 | documento =(int) (Math.random() * 100000000); | |
| 30 | cargarFechaRandom(fecha = new int[3]); | |
| 31 | correo = correoRandom(); | |
| 32 | numeroClular = (int) (Math.random() * 10000000); | |
| 33 | datos = new Persona(apellido, nombre, documento, fecha, correo, numeroClular); | |
| 34 | listaDePersonas.add(datos); | |
| 35 | ||
| 36 | } | |
| 37 | ||
| 38 | continuar = valiadarOpcion(entrada); | |
| 39 | } | |
| 40 | for (Persona PeronasRegistradas : listaDePersonas){
| |
| 41 | System.out.println(PeronasRegistradas); | |
| 42 | } | |
| 43 | rangoAños(listaDePersonas); | |
| 44 | } | |
| 45 | ||
| 46 | private static String valiadarOpcion(Scanner entrada){
| |
| 47 | System.out.println("¿Desea Continuar? [s/n]");
| |
| 48 | String opcion = entrada.nextLine(); | |
| 49 | while(!(opcion.equalsIgnoreCase("s")||opcion.equalsIgnoreCase("n"))){
| |
| 50 | System.out.println("Opcion Incorrecta");
| |
| 51 | System.out.println("¿Desea Continuar? [s/n]");
| |
| 52 | opcion = entrada.nextLine(); | |
| 53 | } | |
| 54 | return opcion; | |
| 55 | } | |
| 56 | ||
| 57 | private static String cargarLetra(Scanner entrada,String mensaje){
| |
| 58 | System.out.println(mensaje); | |
| 59 | String linea=entrada.nextLine(); | |
| 60 | while(validarLetras(linea)){
| |
| 61 | System.out.println("''ERROR'' No Ingresar Numeros");
| |
| 62 | System.out.println(mensaje); | |
| 63 | linea=entrada.nextLine(); | |
| 64 | } | |
| 65 | ||
| 66 | return linea; | |
| 67 | } | |
| 68 | ||
| 69 | public static boolean validarLetras(String linea) {
| |
| 70 | for (int x = 0; x < linea.length(); x++) {
| |
| 71 | char c = linea.charAt(x); | |
| 72 | // Si no está entre a y z, ni entre A y Z, ni es un espacio | |
| 73 | if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == ' ')) {
| |
| 74 | return true; | |
| 75 | } | |
| 76 | } | |
| 77 | return false; | |
| 78 | } | |
| 79 | ||
| 80 | public static int cargarDocumento(){
| |
| 81 | Scanner entrada = new Scanner(System.in); | |
| 82 | int numeroDocumento= Modulo.validarNumero(entrada, "Ingrese Numero de Documento: xxxxxxxx"); | |
| 83 | while(!(validarDocumento(numeroDocumento))){
| |
| 84 | System.out.println("el documento debe tener 8 cifras");
| |
| 85 | numeroDocumento= Modulo.validarNumero(entrada, "Ingrese Numero de Documento: xxxxxxxx"); | |
| 86 | } | |
| 87 | ||
| 88 | return numeroDocumento; | |
| 89 | } | |
| 90 | ||
| 91 | public static boolean validarDocumento(int numeroDocumento){
| |
| 92 | String cifras = Integer.toString(numeroDocumento); | |
| 93 | if (cifras.length()==8){
| |
| 94 | return true; | |
| 95 | } | |
| 96 | else{
| |
| 97 | return false; | |
| 98 | } | |
| 99 | } | |
| 100 | ||
| 101 | public static void cargarFecha(int [] fecha, Scanner entrada){
| |
| 102 | int dia,mes,año; | |
| 103 | dia = Modulo.validarNumero(entrada, "Ingresar Dia [1/31]"); | |
| 104 | mes = Modulo.validarNumero(entrada, "Ingresar Mes: [1/12]"); | |
| 105 | año = Modulo.validarNumero(entrada, "Ingresar Año: [1930/2021]"); | |
| 106 | while(!(validarFecha(dia, mes, año))){
| |
| 107 | System.out.println("Ingrese los Datos Nuevamente");
| |
| 108 | dia = Modulo.validarNumero(entrada, "Ingresar Dia [1/31]"); | |
| 109 | mes = Modulo.validarNumero(entrada, "Ingresar Mes: [1/12]"); | |
| 110 | año = Modulo.validarNumero(entrada, "Ingresar Año: [1930/2021]"); | |
| 111 | } | |
| 112 | fecha[0] = dia; | |
| 113 | fecha[1] = mes; | |
| 114 | fecha[2] = año; | |
| 115 | } | |
| 116 | ||
| 117 | public static boolean validarFecha(int dia ,int mes,int año){
| |
| 118 | String lineaDia,lineaMes,lineaAño; | |
| 119 | boolean validar = true; | |
| 120 | lineaDia = Integer.toString(dia); | |
| 121 | lineaMes = Integer.toString(mes); | |
| 122 | lineaAño = Integer.toString(año); | |
| 123 | if(lineaDia.length()<=2 && dia>=1 && dia<=31){
| |
| 124 | if(lineaMes.length()<=2 && mes>=1 && mes<=12){
| |
| 125 | if(lineaAño.length()==4 && año>=1930 && año<=2021){
| |
| 126 | validar = true; | |
| 127 | } | |
| 128 | else{
| |
| 129 | System.out.println("El Año ingresado es incorrecto");
| |
| 130 | validar = false; | |
| 131 | } | |
| 132 | } | |
| 133 | else{
| |
| 134 | System.out.println("El Mes ingresado es incorrecto");
| |
| 135 | validar = false; | |
| 136 | } | |
| 137 | } | |
| 138 | else{
| |
| 139 | System.out.println("El Dia ingresado es incorrecto");
| |
| 140 | validar = false; | |
| 141 | } | |
| 142 | return validar; | |
| 143 | } | |
| 144 | ||
| 145 | public static String cargarCorreo(Scanner entrada) {
| |
| 146 | System.out.println("ingresar correo");
| |
| 147 | String correo = entrada.nextLine(); | |
| 148 | while (!(correo.contains("@") && correo.contains("."))){
| |
| 149 | System.out.println("ingresar correo con @ y .");
| |
| 150 | correo = entrada.nextLine(); | |
| 151 | } | |
| 152 | return correo; | |
| 153 | } | |
| 154 | ||
| 155 | public static int cargarNumeroCelular() {
| |
| 156 | Scanner entrada = new Scanner(System.in); | |
| 157 | int numeroClular = Modulo.validarNumero(entrada, "Ingrese Numero de Celular sin (+54)388"); | |
| 158 | while (!(validarNumeroCelular(numeroClular))){
| |
| 159 | System.out.println("''ERROR''");
| |
| 160 | numeroClular = Modulo.validarNumero(entrada, "Ingrese Numero de Celular sin (+54)388"); | |
| 161 | } | |
| 162 | return numeroClular; | |
| 163 | } | |
| 164 | ||
| 165 | public static boolean validarNumeroCelular(int numeroClular) {
| |
| 166 | String numero = Integer.toString(numeroClular); | |
| 167 | if (numero.length()==7){
| |
| 168 | return true; | |
| 169 | } | |
| 170 | else{
| |
| 171 | return false; | |
| 172 | } | |
| 173 | } | |
| 174 | ||
| 175 | public static void rangoAños(ArrayList<Persona> listaDePersonas) {
| |
| 176 | Scanner entrada = new Scanner(System.in); | |
| 177 | int desde,hasta; | |
| 178 | int[] año; | |
| 179 | System.out.println("Rango de Edad[1930/2021]");
| |
| 180 | desde = Modulo.validarNumero(entrada,"Mostrar rango de edad desde"); | |
| 181 | hasta = Modulo.validarNumero(entrada,"hasta"); | |
| 182 | while (!(validarRango(desde,hasta))){
| |
| 183 | System.out.println("''ERROR'' Ingrese los Datos Nuevamente");
| |
| 184 | desde = Modulo.validarNumero(entrada,"Mostrar rango de edad desde"); | |
| 185 | hasta = Modulo.validarNumero(entrada,"hasta"); | |
| 186 | } | |
| 187 | System.out.println("Mostrando Lista de Personas["+desde+","+hasta+"]");
| |
| 188 | for (int i=0;i<listaDePersonas.size();i++){
| |
| 189 | año = listaDePersonas.get(i).getFecha(2); | |
| 190 | if (año[2]>desde && año[2]<hasta){
| |
| 191 | System.out.println(listaDePersonas.get(i)); | |
| 192 | } | |
| 193 | } | |
| 194 | } | |
| 195 | ||
| 196 | public static boolean validarRango(int desde, int hasta) {
| |
| 197 | String lineaDesde,lineaHasta; | |
| 198 | lineaDesde = Integer.toString(desde); | |
| 199 | lineaHasta = Integer.toString(hasta); | |
| 200 | if (lineaDesde.length()==4 && desde<hasta && desde>=1930 && desde<=2021){
| |
| 201 | if (lineaHasta.length()==4 && hasta>=1930 && hasta<=2021){
| |
| 202 | return true; | |
| 203 | } | |
| 204 | else{
| |
| 205 | return false; | |
| 206 | } | |
| 207 | } | |
| 208 | else{
| |
| 209 | return false; | |
| 210 | } | |
| 211 | } | |
| 212 | ||
| 213 | public static String apellidoRandom(){
| |
| 214 | int random; | |
| 215 | String [] apellido ={"Fernández","López ","Martínez ","Sánchez","Pérez","Gómez","Serapio","Gutierrez","Zerpa","Soruco"};
| |
| 216 | random = (int) (Math.random() * apellido.length); | |
| 217 | return apellido[random]; | |
| 218 | } | |
| 219 | ||
| 220 | public static String nombreRandom(){
| |
| 221 | int random; | |
| 222 | String [] nombre ={"Fernanda","Lorena ","Martín ","Sara","Pedro","Gabriel","Gerardo","Lis","Catriel","Camila"};
| |
| 223 | random = (int) (Math.random() * nombre.length); | |
| 224 | return nombre[random]; | |
| 225 | } | |
| 226 | ||
| 227 | public static void cargarFechaRandom(int [] fecha){
| |
| 228 | int dia,mes,año; | |
| 229 | dia =(int) (Math.random()*30+1); | |
| 230 | mes = (int) (Math.random()*11+1); | |
| 231 | año = (int) (Math.random()*2021); | |
| 232 | while(!(validarFechaRandom(dia, mes, año))){
| |
| 233 | dia =(int) (Math.random()*30+1); | |
| 234 | mes = (int) (Math.random()*11+1); | |
| 235 | año = (int) (Math.random()*2021); | |
| 236 | } | |
| 237 | fecha[0] = dia; | |
| 238 | fecha[1] = mes; | |
| 239 | fecha[2] = año; | |
| 240 | } | |
| 241 | ||
| 242 | public static boolean validarFechaRandom(int dia ,int mes,int año){
| |
| 243 | String lineaDia,lineaMes,lineaAño; | |
| 244 | boolean validar = true; | |
| 245 | lineaDia = Integer.toString(dia); | |
| 246 | lineaMes = Integer.toString(mes); | |
| 247 | lineaAño = Integer.toString(año); | |
| 248 | if(lineaDia.length()<=2 && dia>=1 && dia<=31){
| |
| 249 | if(lineaMes.length()<=2 && mes>=1 && mes<=12){
| |
| 250 | if(lineaAño.length()==4 && año>=1930 && año<=2021){
| |
| 251 | validar = true; | |
| 252 | } | |
| 253 | else{
| |
| 254 | validar = false; | |
| 255 | } | |
| 256 | } | |
| 257 | else{
| |
| 258 | validar = false; | |
| 259 | } | |
| 260 | } | |
| 261 | else{
| |
| 262 | validar = false; | |
| 263 | } | |
| 264 | return validar; | |
| 265 | } | |
| 266 | ||
| 267 | public static String correoRandom(){
| |
| 268 | int random; | |
| 269 | String [] correo ={"[email protected]","[email protected] ","[email protected] ","[email protected]",
| |
| 270 | "[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]"}; | |
| 271 | random = (int) (Math.random() * correo.length); | |
| 272 | return correo[random]; | |
| 273 | } | |
| 274 | } |