title: Fish Pond Simulation: Homework, where am I going wrong?
body: <p>This is a multipart question.</p>
  
  <p>Restrictions:</p>
  
  <ul>
  <li>can't use <code>.clone()</code>, or <code>Collections</code>, or <code>System</code>.</li>
  <li>can't change to a different object type (I mean I can't change the <code>ArrayList</code> to a <code>List</code> or what not).</li>
  </ul>
  
  <p>I think my problem might be that I haven't grasped exactly how to throw exceptions.
  Not sure though.</p>
  
  <p>Here is a part of the assignment that I'm stuck on.</p>
  
  <blockquote>
    <p>Adds the fish f to the fish list, if possible.</p>
    
    <p>First checks if the landscape in the fish's location is equal to ROCK.
    If it is, then the fish is not added to the list.  Instead, throws an
    IllegalFishPositionException, passing 
    <code>IllegalFishPositionException.FISH_OVER_ROCK</code> to the constructor.
    <p>
    Next checks for another fish (distinct from the parameter) that is in
    the same location as the parameter.  If one is found, then the fish is
    not added to the list.  Instead throws an IllegalFishPositionException,
    passing <code>IllegalFishPositionException.TWO_FISH_IN_ONE_PLACE</code> to the
    constructor.
    <p>
    Otherwise, adds the parameter to the fish list.</p>
  </blockquote>
  
  <pre><code>public void addFish(Fish f) {
      ArrayList &lt;Fish&gt; addFish = new ArrayList &lt;Fish&gt;( fish );
  
      if ( landscape[ f.getRow() ][ f.getCol() ] == ROCK ) {
          throw new IllegalFishPositionException(
                  IllegalFishPositionException.FISH_OVER_ROCK );
      }
      for ( Fish f1 : addFish ) {
          if ( ( f1.getRow() == f.getRow() &amp;&amp; 
                  f1.getCol() == f.getCol() ) || f1 == f ) {
              throw new IllegalFishPositionException(
                      IllegalFishPositionException.TWO_FISH_IN_ONE_PLACE );
          }
      }
      for ( Fish f2 : addFish ) {
          if ( ( f2.getRow() != f.getRow() &amp;&amp; 
                  f2.getCol() != f.getCol() ) &amp;&amp; 
                  landscape[ f.getRow() ][ f.getCol() ] != ROCK ) {
              fish.add( f );
          }
      }
  
  }
  </code></pre>
  
  <p>And here is the second method that seems logical to me, but is failing on tests.</p>
  
  <pre><code>/* Checks the specified location to see if it has a rock, fish, or plant 
   * in it. If so, returns false; if it is just water, returns true. */
  public boolean isSpaceAvailable(int r, int c) {
      if ( landscape[r][c] == ROCK ) {
          return false;
      }
      for ( Fish f : fish ) {
          if ( ( f.getRow() == r ) &amp;&amp; ( f.getCol() == c ) ) {
              return false;
          }
      }
      for ( Plant p : plants ) {
          if ( ( p.getRow() == r ) &amp;&amp; ( p.getCol() == c ) ) {
              return false;
          }
      }
      return true;
  }
  </code></pre>
  
  <p>I have a couple of other methods that are dependent on addFish, so if I can get it right, it'll have a cascading effect.</p>
  
  <p>Here is the JUnit test I need to pass for the isSpaceAvailable method.</p>
  
  <pre><code>@Test
  public void testIsSpaceAvailable() {
      Model m = new Model(10,10,0,0,0);
      Fish f = new Fish(1, 7, 100, Fish.UP);
      Plant p = new Plant(2, 8, 100);
      m.addFish(f);
      m.addPlant(p);
      assertFalse(m.isSpaceAvailable(1, 7));
      assertFalse(m.isSpaceAvailable(2, 8));
      assertFalse(m.isSpaceAvailable(0, 0));
      for (int i = 1; i &lt; 9; i++) {
          for (int j = 1; j &lt; 9; j++) {
              if ((i != 1 || j != 7) &amp;&amp; (i != 2  || j != 8)) {
                  assertTrue(m.isSpaceAvailable(i, j));
              }
          }
      }
  }
  </code></pre>
  
  <p>Here is the JavaDoc for the project if you guys need to look through it.
  <a href="http://www.cs.umd.edu/class/spring2013/cmsc131-23/Projects/P7/doc/index.html" rel="nofollow">http://www.cs.umd.edu/class/spring2013/cmsc131-23/Projects/P7/doc/index.html</a></p>
  
  <p>I've been staring at this for a while and I'm throughly stuck.</p>