I'm trying to write a method that takes a y-coordinate as a parameter and returns the object at that y-coordinate. I'm supposed to write it with a loop which still kind of confuses me. Any help would be appreciated.
public Minnow getMinnowAtHeight(int yPosition)
{
ocean = new Ocean();
for (int i = 0; i <= ocean.getWidth(); i++)
minnow = (Minnow)ocean.getOneObjectAt(i, yPosition);
if (minnow == null)
{
return null;
}
return minnow;
}