8
I created a state class with name, acronym and capital and a country with name, capital and states - an Arraylist of the type State.
I want to create an input methodState(and status) that before adding the state in a Country, checks if it has not already been added before and displays a message. I thought that way:
public void adicionaEstado(Estado e){
for(int i=0; i < estados.size(); i++){
if (estados.get(i).getNome().equals(e.getNome())){
System.out.println("Esse estado já foi adicionado ao país anteriormente.");
}
else{
estados.add(e);
System.out.println("Estado adicionado.");
}
}
}
Although it is not a mistake, it is not adding the elements. Also, I would like to know how the signature of the method would have to be for me to be able to return these messages.
if(estados.contains(e)){...}
– Renan Gomes