· 4 years ago · Sep 11, 2021, 09:44 PM
1import estructuradedatos.tp1.Persona;
2
3import java.util.Scanner;
4
5public class Ejercicio5 {
6
7 public static void main(String[] args) {
8
9 Scanner Teclado = new Scanner(System.in);
10
11 String Numero;
12
13 do {
14
15 System.out.println("Cantidad de personas a registrar");
16
17 Numero = Teclado.next();
18
19 } while (ValidarNumero(Numero) == false);
20
21 Persona[] Personas = new Persona[Integer.parseInt(Numero)];
22
23 String[] Nombre = { "Andrea", "David", "Baldomero", "Balduino", "Baldwin", "Baltasar", "Barry", "Bartolo","Bartolomé", "Baruc", "Baruj", "Candelaria", "Cándida", "Canela", "Caridad", "Carina", "Carisa","Caritina", "Carlota", "Baltazar"};
24
25 String[] Apellido = { "Gomez", "Guerrero", "Cardenas", "Cardiel", "Cardona", "Cardoso", "Cariaga", "Carillo","Carion", "Castiyo", "Castorena", "Castro", "Grande", "Grangenal", "Grano", "Grasia", "Griego","Grigalva", "Gaspar", "Gaspari"};
26
27 Cargar(Personas, Teclado, Nombre, Apellido);
28
29 RangoAño(Personas, Teclado);
30 }
31
32 // ///////////////////////////////////////////////////////////////FUNCIONES/////////////////////////////////////////////////////////////////
33
34 public static boolean ValidarNumero(String Numero) {
35
36 try {
37
38 Integer.parseInt(Numero);
39
40 return true;
41
42 } catch (NumberFormatException exeption) {
43
44 return false;
45 }
46 }
47
48 // /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
49
50 static void Cargar(Persona[] Persona, Scanner Teclado, String[] NombreRandom, String[] ApellidoRandom) {
51
52 String Numero;
53
54 for (int i = 0; i < Persona.length; i++) {
55
56 Persona[i] = new Persona();
57
58 System.out.println("¿Generar persona aleatoria " + (i+1) + "? S/N");
59
60 String Respuesta = Teclado.next();
61
62 if (Respuesta.equalsIgnoreCase("S")) {
63
64 Persona[i].SetNombre(NombreRandom[(int)(Math.random()*19)]);
65
66 Persona[i].SetApellido(ApellidoRandom[(int)(Math.random()*19)]);
67
68 Persona[i].SetDocumento((int)(Math.random()*(29999999+10000000)));
69
70 Persona[i].SetAño((int)(Math.random()*221+1800));
71
72 Persona[i].SetCorreo(CorreoRandom());
73
74 Persona[i].SetNumeroCelular((int)(Math.random()*(999999+388000000)));
75
76 } else {
77
78 System.out.println("Ingrese nombre");
79
80 String Nombre = Teclado.next();
81
82 Persona[i].SetNombre(Nombre);
83
84 System.out.println("Ingrese apellido");
85
86 String Apellido = Teclado.next();
87
88 Persona[i].SetApellido(Apellido);
89
90 do {
91
92 System.out.println("Ingrese documento");
93
94 Numero = Teclado.next();
95
96 } while (ValidarNumero(Numero) == false);
97
98 int Documento = Integer.parseInt(Numero);
99
100 Persona[i].SetDocumento(Documento);
101
102 do {
103
104 System.out.println("Ingrese año de nacimiento");
105
106 Numero = Teclado.next();
107
108 } while (ValidarNumero(Numero) == false);
109
110 int Año = Integer.parseInt(Numero);
111
112 Persona[i].SetAño(Año);
113
114 System.out.println("Ingrese correo electrónico");
115
116 String Correo = Teclado.next();
117
118 Persona[i].SetCorreo(Correo);
119
120 do {
121
122 System.out.println("Ingrese numero de celular");
123
124 Numero = Teclado.next();
125
126 } while (ValidarNumero(Numero) == false);
127
128 int NumeroCelular = Integer.parseInt(Numero);
129
130 Persona[i].SetNumeroCelular(NumeroCelular);
131 }
132 }
133 }
134
135 // /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
136
137 public static String CorreoRandom() {
138
139 String Caracteres = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789";
140
141 String cadena = " ";
142
143 for(int i = 0; i < ((int)(Math.random()*14+10)); i++) {
144
145 int Indice = (int)(Math.random()*(Caracteres.length() - 1));
146
147 char CaracterAleatorio = Caracteres.charAt(Indice);
148
149 cadena += CaracterAleatorio;
150
151 }
152
153 return cadena;
154
155 }
156
157///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
158
159 static void RangoAño(Persona[] Persona, Scanner Teclado) {
160
161 int ii = 0;
162
163 String Numero;
164
165 System.out.println("Ingrese rango de años");
166
167 System.out.println("Mínimo año");
168
169 do {
170
171 Numero = Teclado.next();
172
173 } while(ValidarNumero(Numero) == false);
174
175 int MinAño = Integer.parseInt(Numero);
176
177 System.out.println(" Máximo año");
178
179 do {
180
181 Numero = Teclado.next();
182
183 } while(ValidarNumero(Numero) == false);
184
185 int MaxAño = Integer.parseInt(Numero);
186
187 System.out.println("(" + MaxAño + "," + MinAño + ") año de nacimiento");
188
189 for(int i = 0; i < Persona.length; i++) {
190
191 if(Persona[i].GetAño() >= MinAño && Persona[i].GetAño() <= MaxAño) {
192
193 System.out.println("PERSONA " + (i+1));
194
195 System.out.println("Nombre: " + Persona[i].GetNombre());
196
197 System.out.println("Apellido:" + Persona[i].GetApellido());
198
199 System.out.println("Documento: " + Persona[i].GetDocumento());
200
201 System.out.println ("Año de nacimiento " + Persona[i].GetAño());
202
203 System.out.println ("Correo: " + Persona[i].GetCorreo() + "@gmail.com");
204
205 System.out.println ("Numero de celular: " + Persona[i].GetNumeroCelular());
206
207 System.out.println("");
208
209 ii++;
210
211 }
212
213 }
214
215 System.out.println("Cantidad de personas encontradas " + ii);
216
217 }
218
219 }
220