I'm trying to check if a name has already been used in the array, but it's only working for the spot [0]. I'm assuming its from the for loop in boolean only going through once and not incrementing up to check the other spots?
Tried changing different if's and while loops
if (depotCount < 4){ // Runs if the depots are less than 4
System.out.println("Enter your depots name");
name = console.next().toLowerCase();
if (check(depots, name) == true){
System.out.println("Depot name already exists");
break;
}
else {
addDepot(depots, name);
}
} else {
System.out.println("Only 4 depots are allowed");
break;
}
public boolean check(Depot [] depots, String name){
boolean check = false;
for (int i = 0; i < depots.length; i++){
if(depots[i].getDepotName().equals(name))
return true;
else {
return false;
}
}
return check;
}
So it is working if a first name as "Warehouse" and I try to put "Warehouse" a second time. but if I try to put the same name as the 2nd slots it doesn't come back as true.
something == true: it's equivalent to use justsomething.