1
I have this exercise below to do put in question "D" I’m struggling , if someone can explain me how I should do :
a) Create an interface called
ModeloContato
with the methodsgetNome()
,getTelefone()
andgetEndereco()
, all without parameters and returningString
,int
andString
respectively;b) Create a concrete class called
Contato
implement the abstract interface methods created in the letter a.Contato
must include methodsset
and the attributesnome
,telefone
andendereço
.c) Create a
ArrayList
of the kindContato
, representing an agenda. Add contacts by assigning initial values to attributes.d) Print the contact details entered in the letter C.
e) Implement the search for a contact on the agenda, printing when the result is found or stating that it was not found if it is the case.
Follow the code already made :
public static void main(String[] args) {
ArrayList<Contato> agenda = new ArrayList<Contato>();
Contato a = new Contato ();
Contato b = new Contato ();
Contato c = new Contato ();
for (int i = 0 ; i < 3; i++){
Contato contato1 = new Contato();
agenda.add(contato1);
agenda.get(i).setNome("joao");
agenda.add(contato1);
agenda.get(i).setEndereco("Rua Joao Camara");
agenda.add(contato1);
agenda.get(i).setTelefone(3589);
}
for(int i = 1; i <= 1; i++){
System.out.println(agenda.get(0).getNome());
System.out.println(agenda.get(0).getEndereco());
System.out.println(agenda.get(0).getTelefone());
}
}
If you could just give me an example of how to do it would be great, if you give me the answer I won’t learn how to do it.
Explain me a little more about Item C friend , I could not assimilate with reply . I must withdraw the first for ?
– Felipe Lamarao
@Felipelamarao as this doubt is about the letter C, it would be more interesting to do this in another question, not to distort the purpose of this. But I also suggest to abstract in a method the part, than to do structural, since I imagine that it is an exercise for learning about POO.
– user28595
Thank you, I’ll do
– Felipe Lamarao