Código:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Agenda {
static InputStreamReader isr = new InputStreamReader(System.in);
static BufferedReader br = new BufferedReader(isr);
static Registro registros[];
public static void main(String[] args)throws IOException {
String opcion;
int i=0;
registros = new Registro [2];
for (i=0; i<registros.length; i++)
registros[i] = null;
System.out.println("1 - Añadir");
System.out.println("2 - Modificar");
System.out.println("3 - eliminiar");
System.out.println("4 - Buscar");
System.out.println("5 - Salir");
opcion = br.readLine();
while (!opcion.equals ("5")){
if (opcion.equals("1"))
agregar();
else if (opcion.equals("2"))
modificar ();
else if (opcion.equals("3"))
eliminar();
else if (opcion.equals("4"))
buscar();
else
System.out.println ("Opción incorrecta..");
System.out.println("1 - Añadir");
System.out.println("2 - Modificar");
System.out.println("3 - eliminiar");
System.out.println("4 - Buscar");
System.out.println("5 - Salir");
opcion = br.readLine();
}
}
static void agregar()throws IOException{
String nombre, localidad, calle, provincia;
int numero, piso, cp, i=0;
char letra;
long telefono;
while (registros [i] != null && i<registros.length)
i++;
if (i<registros.length){
System.out.print("Nombre: ");
nombre = br.readLine();
System.out.print("Calle: ");
calle = br.readLine();
System.out.print("Numero: ");
numero = Integer.parseInt(br.readLine());
System.out.print("Piso: ");
piso = Integer.parseInt(br.readLine());
System.out.print("Letra: ");
letra = br.readLine().charAt(0);
System.out.print("Codigo postal: ");
cp = Integer.parseInt(br.readLine());
System.out.print("Localidad: ");
localidad = br.readLine();
System.out.print("Provincia: ");
provincia = br.readLine();
System.out.print("Telefono: ");
telefono = Long.parseLong(br.readLine());
Direccion aux = new Direccion(calle, numero, piso,
letra, cp, localidad, provincia);
registros[i]= new Registro(nombre, aux, telefono);
}
}
static void modificar() throws IOException {
String nombre, localidad, calle, provincia;
int numero, piso, cp ;
char letra;
long telefono;
System.out.print("Nombre: ");
nombre = br.readLine();
for (int i = 0; i < registros.length; i++) {
if (!registros[i].getNombre().equals(nombre))
System.out.println("No existe ese registro");
else {
registros[i].getNombre() .equals(nombre);
System.out.print("Nuevo Nombre: ");
nombre = br.readLine();
System.out.print("Nueva Calle: ");
calle = br.readLine();
System.out.print("Nuevo Numero: ");
numero = Integer.parseInt(br.readLine());
System.out.print("Nuevo Piso: ");
piso = Integer.parseInt(br.readLine());
System.out.print("Nueva Letra: ");
letra = br.readLine().charAt(0);
System.out.print("Nuevo Codigo postal: ");
cp = Integer.parseInt(br.readLine());
System.out.print("Nueva Localidad: ");
localidad = br.readLine();
System.out.print("Nueva Provincia: ");
provincia = br.readLine();
System.out.print("Nuevo Telefono: ");
telefono = Long.parseLong(br.readLine());
}
break;}
}
static void buscar() throws IOException {
String nombre;
System.out.print("Nombre: ");
nombre = br.readLine();
for (int i = 0; i < registros.length; i++) {
if (!registros[i].getNombre().equals(nombre))
System.out.println("No existe ese registro");
else{
registros[i].getNombre() .equals(nombre);
System.out.println("Nombre: "+registros[i].getNombre());
Direccion dirTemp = registros[i].getDireccion();
System.out.println("Calle: "+dirTemp.getCalle());
System.out.println("Codigo Postal: "+dirTemp.getCp());
System.out.println("Localidad: "+dirTemp.getLocalidad());
System.out.println("Provincia: "+dirTemp.getProvincia());
System.out.println("Piso: "+dirTemp.getPiso());
System.out.println("Letra: "+dirTemp.getLetra());
System.out.println("Telefono: "+registros[i].getTelefono());
}
break;}
}
static void eliminar() throws IOException {
String nombre;
System.out.print("Nombre: ");
nombre = br.readLine();
for (int i = 0; i < registros.length; i++) {
if (!registros[i].getNombre().equals(nombre))
System.out.println("No existe ese registro");
else
{
registros[i]=null;
System.out.println("El registro ha sido borrado correctamente");
}
break;
}
}
static void salir()throws IOException{
return;}
}
import java.io.IOException;
import java.io.InputStreamReader;
public class Agenda {
static InputStreamReader isr = new InputStreamReader(System.in);
static BufferedReader br = new BufferedReader(isr);
static Registro registros[];
public static void main(String[] args)throws IOException {
String opcion;
int i=0;
registros = new Registro [2];
for (i=0; i<registros.length; i++)
registros[i] = null;
System.out.println("1 - Añadir");
System.out.println("2 - Modificar");
System.out.println("3 - eliminiar");
System.out.println("4 - Buscar");
System.out.println("5 - Salir");
opcion = br.readLine();
while (!opcion.equals ("5")){
if (opcion.equals("1"))
agregar();
else if (opcion.equals("2"))
modificar ();
else if (opcion.equals("3"))
eliminar();
else if (opcion.equals("4"))
buscar();
else
System.out.println ("Opción incorrecta..");
System.out.println("1 - Añadir");
System.out.println("2 - Modificar");
System.out.println("3 - eliminiar");
System.out.println("4 - Buscar");
System.out.println("5 - Salir");
opcion = br.readLine();
}
}
static void agregar()throws IOException{
String nombre, localidad, calle, provincia;
int numero, piso, cp, i=0;
char letra;
long telefono;
while (registros [i] != null && i<registros.length)
i++;
if (i<registros.length){
System.out.print("Nombre: ");
nombre = br.readLine();
System.out.print("Calle: ");
calle = br.readLine();
System.out.print("Numero: ");
numero = Integer.parseInt(br.readLine());
System.out.print("Piso: ");
piso = Integer.parseInt(br.readLine());
System.out.print("Letra: ");
letra = br.readLine().charAt(0);
System.out.print("Codigo postal: ");
cp = Integer.parseInt(br.readLine());
System.out.print("Localidad: ");
localidad = br.readLine();
System.out.print("Provincia: ");
provincia = br.readLine();
System.out.print("Telefono: ");
telefono = Long.parseLong(br.readLine());
Direccion aux = new Direccion(calle, numero, piso,
letra, cp, localidad, provincia);
registros[i]= new Registro(nombre, aux, telefono);
}
}
static void modificar() throws IOException {
String nombre, localidad, calle, provincia;
int numero, piso, cp ;
char letra;
long telefono;
System.out.print("Nombre: ");
nombre = br.readLine();
for (int i = 0; i < registros.length; i++) {
if (!registros[i].getNombre().equals(nombre))
System.out.println("No existe ese registro");
else {
registros[i].getNombre() .equals(nombre);
System.out.print("Nuevo Nombre: ");
nombre = br.readLine();
System.out.print("Nueva Calle: ");
calle = br.readLine();
System.out.print("Nuevo Numero: ");
numero = Integer.parseInt(br.readLine());
System.out.print("Nuevo Piso: ");
piso = Integer.parseInt(br.readLine());
System.out.print("Nueva Letra: ");
letra = br.readLine().charAt(0);
System.out.print("Nuevo Codigo postal: ");
cp = Integer.parseInt(br.readLine());
System.out.print("Nueva Localidad: ");
localidad = br.readLine();
System.out.print("Nueva Provincia: ");
provincia = br.readLine();
System.out.print("Nuevo Telefono: ");
telefono = Long.parseLong(br.readLine());
}
break;}
}
static void buscar() throws IOException {
String nombre;
System.out.print("Nombre: ");
nombre = br.readLine();
for (int i = 0; i < registros.length; i++) {
if (!registros[i].getNombre().equals(nombre))
System.out.println("No existe ese registro");
else{
registros[i].getNombre() .equals(nombre);
System.out.println("Nombre: "+registros[i].getNombre());
Direccion dirTemp = registros[i].getDireccion();
System.out.println("Calle: "+dirTemp.getCalle());
System.out.println("Codigo Postal: "+dirTemp.getCp());
System.out.println("Localidad: "+dirTemp.getLocalidad());
System.out.println("Provincia: "+dirTemp.getProvincia());
System.out.println("Piso: "+dirTemp.getPiso());
System.out.println("Letra: "+dirTemp.getLetra());
System.out.println("Telefono: "+registros[i].getTelefono());
}
break;}
}
static void eliminar() throws IOException {
String nombre;
System.out.print("Nombre: ");
nombre = br.readLine();
for (int i = 0; i < registros.length; i++) {
if (!registros[i].getNombre().equals(nombre))
System.out.println("No existe ese registro");
else
{
registros[i]=null;
System.out.println("El registro ha sido borrado correctamente");
}
break;
}
}
static void salir()throws IOException{
return;}
}





Autor




En línea

