I am working on an class lab and ran into some trouble. We have been asked to write a method with the following instructions:
"Dog getRandomDog() - randomly selects a dog, returns it, and removes it from the kennel. Returns null if there are no dogs."
This is the method that I wrote (which doesn't work):
public Dog getRandomDog(){
if(dogs.size() >= 0){
Random random = new Random();
int index = random.nextInt(dogs.size());
return dogs.get(index);
dogs.remove(index);
}
else {
return null;
}
}
I do understand that you cant have an executable statement after a return, but then how the heck to do you around this? Thanks in advance.