7
How would I search for a record within my object?
The program is a schedule of contacts, and I wanted him to do the search by the name I type in a Jpane and return the contact data searched. Here is the commented code.
package ExemploDeAula;
public class Agenda {
//Define um vetor de objetos do tipo contato
private Contato[] lstContatos;
private int qtd;
public void inicializar(){
lstContatos = new Contato[10];
qtd = 0;
}
public boolean inserir(Contato novoContato){
// Verificar se não está cheio
if (qtd>=10){ //se está cheio
return false; //falhou
}
//atribuir o novoContato em uma posição livre
else{
lstContatos[qtd]= novoContato;
qtd++;
return true;
}
}
public boolean remover(Contato contato){
return false;
}
public String pesquisar(String nome){
int i;
String dados;
//procurar pelo nome entre os contatos e
for (i=0;i<=qtd;i++){
if (nome.equals(Contato.getNome())){
}
}
//retornar o objeto correspondente
return dados;
}
}
Yes, I want him to return the String corresponding to the name he searched for, as in the array I have a position for each contact, it would be easy for him to return the email and the phone, which are the other attributes of the contact class.
– Gabriel Orlando
Returning what you’ve been through doesn’t make sense, but if you want to do it even works, you understand what you should do.
– Maniero