So far I've been able to do it, but the imprimiAgenda()
method is printing, but at the same time giving null pointer. And I also want to know if my logic is going well. If you can help me, I'd appreciate it! Another question, how do I get the getters and setters of arrays? For the setter I even managed to do, without any problem, since the getter was a problem, because it needed a return.
package exercicio;
public class Agenda {
private String nome[] = new String [5];
private int idade [] = new int [5];
private float altura [] = new float [5];
public void armazenaAgenda (String nome, int idade, float altura) {
for (int c=0; c<=5; c++) {
if(this.nome[c] == null || this.nome[c].isEmpty()) {
this.nome[c] = nome;
this.idade[c] = idade;
this.altura[c] = altura;
break;
}
}
}
public void imprimiAgenda () {
for (int c=0; c<=5; c++){
System.out.println("Nome: " + this.nome[c]);
System.out.println("Idade: " + this.idade[c]);
System.out.println("Altura: " + this.altura[c]);
System.out.println("------------------");
}
}
public void buscarIndex(int i) {
for (int c=0; c<=5; c++ ){
if(this.nome[c] == this.nome[i]) {
System.out.println("Nome: " + this.nome[i]);
System.out.println("Idade: " + this.idade[i]);
System.out.println("Altura: " + this.altura[i]);
break;
}
}
}
public void buscarNome (String nome) {
for (int c=0; c<=5; c++){
if (this.nome[c] == nome) {
System.out.println(nome + " esta na posicaçao: " + c);
break;
}
}
}