Ho un problema! Quando ho un ArrayList<Contatto> come faccio a farmi stampare in uscita tutta la lista dei contatti?
In tanto vi facico vedere come stò procedendo.
Contatto
codice:
public class Contatto {
private String nome;
private String cognome;
private String numero;
private String note;
private String indirizzo;
public Contatto (String nome,String cognome, String numero, String note, String indirizzo){
this.nome=nome;
this.cognome=cognome;
this.numero=numero;
this.indirizzo=indirizzo;
this.note=note;
}
public String getNome(){
return nome;
}
public String getCognome(){
return cognome;
}
public String getNum(){
return numero;
}
public String getNote(){
return note;
}
public String getInd(){
return indirizzo;
}
public void show(){
System.out.println(nome+
" "+cognome+
" "+numero+
" "+indirizzo+
" "+note);
}
public void delete(){
nome=cognome=indirizzo=note=numero=null;
}
public void modifica(String num, String not, String addr ){
this.numero=num;
this.note=not;
this.indirizzo=addr;
}
}
Rubrica
codice:
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
public class Rubricaa {
private static ArrayList<Contatto> con;
//private ObjectOutputStream fileOut=Rubrica.txt;
//private static ObjectInputStream fileIn=Rubrica.txt;
public Rubricaa(){
con = new ArrayList<Contatto>();
}
public void addCon(Contatto c)throws Exception {
boolean found = false;
for(Contatto p: con){
if (p.getNome().equals(c.getNome())&& p.getCognome().equals(c.getCognome())|| p.getNum().equals(c.getNum())){
found = true;
c.show();
}
}
if(!found)con.add(c);
else throw new Exception();
}
public void vediCon(Contatto c){
boolean found = false;
for(Contatto p: con){
if (p.getNome().equals(c.getNome())&& p.getCognome().equals(c.getCognome())|| p.getNum().equals(c.getNum())){
found = true;
c.show();
}
}
System.out.println("Il contatto non è presente in rubrica");
}
public void del(Contatto c){
for(Contatto p: con){
if(p.getNome().equals(c.getNome())|| p.getCognome().equals(c.getCognome())|| p.getNum().equals(c.getNum())){
c.delete();
}
}
}
public void mod(Contatto c,String num,String notes,String addres){
boolean found = false;
for(Contatto p: con){
if (p.getNome().equals(c.getNome())&& p.getCognome().equals(c.getCognome())|| p.getNum().equals(c.getNum())){
found = true;
c.modifica(num,notes,addres);
}
}
}
public void vediRubrica(ArrayList<Contatto> a){
}
}