



Prepara tus exámenes y mejora tus resultados gracias a la gran cantidad de recursos disponibles en Docsity
Gana puntos ayudando a otros estudiantes o consíguelos activando un Plan Premium
Esta página no es visible en la vista previa
¡No te pierdas las partes importantes!




package agenda; import java.util.*;
public class Persona {
String Nombre=""; String Apellidos=""; String Email=""; String Telefono="";
//muestra el contacto public static void MostrarPersona(ArrayList
System. out .println("Has seleccionado la opción 5. Elija ahora la opción de búsqueda que desea ejecutar:"+"\n"); System. out .println(" a. Búsqueda por nombre"); System. out .println(" b. Búsqueda por apellido"); System. out .println(" c. Búsqueda poe email"); System. out .println(" d. Búsqueda poe teléfono"); System. out .println(" e. Búsqueda poe teléfono");
Scanner entrada = new Scanner(System. in ); String frase = entrada.nextLine(); int numletrasfrase = frase.length(); char posicionletra = frase.charAt(0);
if (posicionletra== 'a'){ System. out .println(" Mostrar por nombre "+"\n"); int i=0;
Iterator it = Contactos.iterator(); if (!it.hasNext()) System. out .println("No hay contactos en la agenda."+"\n"); else while (it.hasNext()) { it.next(); System. out .println("Entrada Nº" +(i+1) +"\n"+ "Nombre: " +Contactos.get (i).Nombre +"\n"); i++ ; }
} else if (posicionletra== 'b'){ System. out .println(" Mostrar por apellidos "+"\n"); int i=0;
Iterator it = Contactos.iterator(); if (!it.hasNext()) System. out .println("No hay contactos en la agenda."+"\n"); else while (it.hasNext()) { it.next(); System. out .println("Entrada Nº" +(i +1) +"\n"+ "Apellidos: " +Contactos.get(i).Apellidos +"\n"); i++ ; } } else if (posicionletra== 'c'){ System. out .println(" Mostrar por email "+"\n"); int i=0;
Iterator it = Contactos.iterator(); if (!it.hasNext()) System. out .println("No hay contactos en la agenda."+"\n"); else while (it.hasNext()) { it.next(); System. out .println("Entrada Nº" +(i+1) +"\n"+ "Email: " +Contactos.get (i).Apellidos +"\n"); i++ ; } } else if (posicionletra== 'c'){ System. out .println(" Mostrar por email "+"\n"); int i=0;
Iterator it = Contactos.iterator(); if (!it.hasNext()) System. out .println("No hay contactos en la agenda."+"\n"); else while (it.hasNext()) { it.next(); System. out .println("Entrada Nº" +(i+1) +"\n"+ "Email: " +Contactos.get(i).Apellidos +"\n"); i++ ;
Scanner leer = new Scanner(System. in );
System. out .println("Ingrese su nombre: "); Datos.Nombre=leer.nextLine().toUpperCase(); System. out .println("Ingrese sus apellido: "); Datos.Apellidos=leer.nextLine().toUpperCase(); System. out .println("Ingrese su email: "); Datos.Email=leer.nextLine().toUpperCase(); System. out .println("Ingrese su telefono: "); Datos.Telefono=leer.nextLine();
Contactos.add(Datos); }
//busca contacto public static void BuscarPersona(ArrayList
Scanner leer = new Scanner(System. in );
System. out .println("Ingrese el nombre para buscar: "); String Nombre=leer.nextLine().toUpperCase();
Iterator it = Contactos.iterator();
while (it.hasNext()) { it.next(); if (Contactos.get(i).Nombre.equals(Nombre)) { j++; System. out .println("Entrada Nº" +(j) +"\n"+ "Nombre: " +Contactos.get (i).Nombre +"\n"+ "Apellido " +Contactos.get (i).Apellidos +"\n"+ "Telefono: " +Contactos.get (i).Telefono +"\n"+ "Email: " +Contactos.get (i).Email +"\n\n"); } i++; } if (j==0) System. out .println("No hay contactos con ese nombre en la agenda."+"\n");
//borra contacto public static void BorrarPersona(ArrayList
int i=0,j=0;
Scanner leer = new Scanner(System. in );
System. out .println("Ingrese el nombre del contacto a eliminar: "); String nombre=leer.nextLine().toUpperCase();
Iterator it = Contactos.iterator(); while (it.hasNext()) { it.next(); if (Contactos.get(i).Nombre.equals(nombre)) { j++; System. out .println("Entrada Nº" +(j) +"\n"+ "Nombre: " +Contactos.get (i).Nombre +"\n"+ " " +Contactos.get (i).Apellidos +"\n"+ "Email: " +Contactos.get (i).Email +"\n"+ "Telefono: " +Contactos.get (i).Telefono +"\n\n");
System. out .println("\n"+"Desea eliminarlo?? [S/N]: "); String confirmacion = leer.nextLine().toUpperCase ();
if (confirmacion.equals("S") || confirmacion.equals ("SI") || confirmacion.equals("Y") || confirmacion.equals("YES")) { it.remove(); break ; } } i++; }
if (j==0) System. out .println("No hay contactos con ese nombre en la agenda."+"\n");