I am trying to define a method called add() that adds an object Fish to an array fish[]. How would I got about this without using arrayList? I keep receiving the error: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
public class Pond {
private Fish[] fish;
private int numFish ;
private int capacity;
public Pond(int capacity){
this.capacity = capacity;
}
public int getNumFish(){ return numFish;
}
public boolean isFull(){//Ponds can only have so many fish
boolean Full = false;
if (numFish >= capacity){
Full = true;}
return Full;
}
public void add(Fish aFish) {// puts a fish in the pond--OR-- replaces a fish that has been temporarily removed
if (numFish < capacity){
fish[numFish++] = aFish;}
}