I created a Cliente
class with attributes name, age, address, cpf. And in the main class I was to make a ArrayList
of type Cliente
, in this way ArrayList Cliente<String> = new ArrayList<>();
in order to create a vector that grows in size as I register Customers.
However, how do I put the information in the attributes of Cliente
of a given index of ArrayList
?
For example, if I have zero index, I wanted to do something like Cliente.nome.add("Joao");
And so I was assigning the values in the same way for attributes age, address, cpf.
Is there any way I can do this? Because in the tutorials of how to make a register that I saw only put type Cliente.add("Joao");
and I did not want to put only name, since I have several attributes to register.
The class I created was like this:
public abstract class Pessoa {
private String nome,sexo,cpf,endereco,email,dataNascimento;
private int telefone;
public String getSexo() {
return sexo;
}
public void setSexo(String sexo) {
this.sexo = sexo;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getDataNascimento() {
return dataNascimento;
}
public void setDataNascimento(String dataNascimento) {
this.dataNascimento = dataNascimento;
}
public int getTelefone() {
return telefone;
}
public void setTelefone(int telefone) {
this.telefone = telefone;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getCpf() {
return cpf;
}
public void setCpf(String cpf) {
this.cpf = cpf;
}
public String getEndereco() {
return endereco;
}
public void setEndereco(String endereco) {
this.endereco = endereco;
}
}
And in the main class I wanted to access my attributes only using ArryList type
public static void main(String[] args) {
ArrayList<String> Cliente = new ArrayList<>();
Cliente.nome.add("Joao");
Obs : Esta linha acima que fiz está errada porque eu nao sei como acessar esses atributos.
}