mirror of
https://gitlab.com/tutorial-java-rafa-munoz/tutorial-java-2024-25/tutorialjava2024-25.git
synced 2025-11-09 18:03:09 +01:00
feat(ch 5): examples & ex added
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
package tutorialJava.capitulo5.ejercicios.bloque01_ArrayPersonas;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Principal {
|
||||
|
||||
private static Persona personas[] = new Persona[3];
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
int opcion = 0;
|
||||
Scanner sc = new Scanner(System.in);
|
||||
|
||||
do {
|
||||
opcion = muestraMenu();
|
||||
|
||||
switch (opcion) {
|
||||
case 1:
|
||||
for (int i = 0; i < personas.length; i++) {
|
||||
personas[i] = new Persona();
|
||||
System.out.println("Introduzca nombre de persona");
|
||||
personas[i].setNombre(sc.nextLine());
|
||||
System.out.println("Introduzca apellidos de persona");
|
||||
personas[i].setApellidos(sc.nextLine());
|
||||
System.out.println("Introduzca dni de persona");
|
||||
personas[i].setDni(sc.nextLine());
|
||||
System.out.println("Introduzca dirección de persona");
|
||||
personas[i].setDireccion(sc.nextLine());
|
||||
System.out.println("Introduzca telefono de persona");
|
||||
personas[i].setTelefono(sc.nextLine());
|
||||
}
|
||||
|
||||
break;
|
||||
case 2:
|
||||
for (int i = 0; i < personas.length; i++) {
|
||||
System.out.println(personas[i].toString());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
} while (opcion != 0);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
public static int muestraMenu() {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
System.out.println("\n\nMenú" +
|
||||
"\n0.- Salir" +
|
||||
"\n1.- Introducir datos" +
|
||||
"\n2.- Visualizar datos" +
|
||||
"\n\tIntroduzca su opción: ");
|
||||
return Integer.parseInt(sc.nextLine());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user