1
I’m doing a method of adding Users, and just one thing isn’t working, the function that:
"Adding friends with the same mobile number will not be allowed."
Ai need to check the users already added, to see if they do not have a mobile number equal to the one that is added.
It’s adding, but it’s also adding users with the same mobile number. And it couldn’t add if the number was equal
public void AdicionaAmigo(Usuario usr)
{
boolean existeEsteNum = false;
if(ListadeAmigos == null || ListadeAmigos.length == 0) {
for(int i=0; i<ListadeAmigos.length; i++){
if(ListadeAmigos[i].getCel() == usr.getCel()){
existeEsteNum = true;
System.out.println ("Já existe um usuário cadastrado com esse número de celular");
break;
}
}
}
if(!existeEsteNum){
if(qtdeAmigos < ListadeAmigos.length)
{
ListadeAmigos[qtdeAmigos++] = usr;
System.out.println ("Usuario adicionado com sucesso!");
} else {
System.out.println ("A lista está cheia");
}
}
}
Please add the code in text form to make it easier to test.
– user28595
And what is the error that returns?
– Max Rogério
And report what is not working. What happens? Under what circumstances?
– Maniero
It’s adding, but it’s also adding users with the same mobile number. And it couldn’t add if the number was equal.
– Daniel
The part of checking the phone is not working, it adds anyway users;
– Daniel