2
I would like to add contacts in a ArrayList
, but adding initial values to the attribute.
First I created a class called contact , and I want to create a contact type Arraylist and I would like to know how to add data to this Arraylist
This is the contact class :
public class Contato implements ModeloContato {
// ATRIBUTOS
private String nome;
private int telefone;
private String endereco;
//METODODOS ESPECIAIS
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public int getTelefone() {
return telefone;
}
public void setTelefone(int telefone) {
this.telefone = telefone;
}
public String getEndereco() {
return endereco;
}
public void setEndereco(String endereco) {
this.endereco = endereco;
}
//METODOS DA INTERFACE
@Override
public void getnome() {
}
@Override
public void gettelefone() {
}
@Override
public void getendereco() {
}
}
this is the main :
public class Main {
public static void main(String[] args) {
ArrayList<Contato> agenda = new ArrayList<Contato>();
Contato a = new Contato ();
Contato b = new Contato ();
Contato c = new Contato ();
Tried to create a method
adicionarContato
how did I explain? I didn’t see this attempt in the code.– user28595
Why are name, phone, and address getters methods repeated? What interface is this? It makes no sense for you to implement an interface and not use anything of it, and still create methods with similar signatures in this way.
– user28595
I was also in doubt about Disso @Articuno , but it was what was requested in the exercise .
– Felipe Lamarao
Where should I put the Add Host ? in the main method ?
– Felipe Lamarao