Está en la página 1de 4

Clases Encapsulacion Java

UV
¡Error! Nombre de archivo no especificado.
uwe villanueva
To:
eryacame@gmail.com; julinho2202@gmail.com; Aldo Elias Villafuerte
Palacios; cristhiandrang@gmail.com; llanoscubasa@gmail.com; bbruno2672@gmail.com; Jezer aguirre
moya; saint_shur4@hotmail.com; Miguel Angel Condezo
Espìnoza; jordan.torres@hotmail.es; cesar96sr@gmail.com; jesus_pizarro998@hotmail.com; david_19_
1997@hotmail.com; kennyxz2397_rg@hotmail.com; 777 lyzork
777; juanquimata@gmail.com; andre_menes27@hotmail.com

Wed 10/23/2019 5:50 PM

View less

/**
*
* @author SaLa2-PROFESOR
*/
public class Contacto {

private String nombre;


private String direccion;
private int codigo;
private String telefono;

public Contacto(String nombre, String direccion, int codigo, String telefono) {


this.nombre = nombre;
this.direccion = direccion;
this.codigo = codigo;
this.telefono = telefono;
}

/**
* @return the nombre
*/
public String getNombre() {
return nombre;
}

/**
* @param nombre the nombre to set
*/
public void setNombre(String nombre) {
this.nombre = nombre;
}

/**
* @return the direccion
*/
public String getDireccion() {
return direccion;
}

/**
* @param direccion the direccion to set
*/
public void setDireccion(String direccion) {
this.direccion = direccion;
}

/**
* @return the codigo
*/
public int getCodigo() {
return codigo;
}

/**
* @param codigo the codigo to set
*/
public void setCodigo(int codigo) {
this.codigo = codigo;
}

/**
* @return the telefono
*/
public String getTelefono() {
return telefono;
}

/**
* @param telefono the telefono to set
*/
public void setTelefono(String telefono) {
this.telefono = telefono;
}

}
================================================
package clase23octubre;

import java.util.ArrayList;

public class Agenda {

private ArrayList<Contacto> ag;

Agenda(ArrayList<Contacto> agx){
this.ag = agx;
}

public ArrayList<Contacto> getAg() {


return ag;
}

public void setAg(ArrayList<Contacto> ag) {


this.ag = ag;
}

void agregarContactos(Contacto x){

this.ag.add(x);
}

int borrarContacto(String nomx){


for(Contacto x : this.ag){
if(nomx == x.getNombre()){

if(this.ag.remove(x)==true){
return 1;
}

}
}
return 0;
}

void mostrarContactos(){
for(Contacto x: this.ag){
System.out.println(x.getNombre() + " " +x.getTelefono());
}
}

}
====================================================
/**
*
* @author SaLa2-PROFESOR
*/
public class Clase23Octubre {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Contacto alumnoFiee = new Contacto("Cesar","Lima",51,"777");
ArrayList<Contacto> claseUNI = new ArrayList<Contacto>();
claseUNI.add(alumnoFiee);
claseUNI.add(new Contacto("jezer","Collique",51,"7777"));

Agenda gx = new Agenda(claseUNI);


gx.mostrarContactos();

Contacto julinho = new Contacto("Julinho","PtePiedra",51,"948989");


gx.agregarContactos(julinho);
System.out.println("\n");
gx.mostrarContactos();

También podría gustarte