title: rear value not working properly in circular array queue
body: <p>I have this code for adding:</p>
  
  <pre><code>public void add(AnyType item){
      if(isEmpty()){
          q[f]=item;
      }
      else{
          if(size==q.length){
              AnyType[] copyQ = (AnyType[]) new Object[q.length*2];
              System.arraycopy(q, f, copyQ, 0, q.length-f);
              System.arraycopy(q, 0, copyQ, q.length-f, r);
              f = 0;
              q = copyQ;
          }
      }
      q[r]=item;
      r = (r+1)%(q.length);
      size++;
  }
  </code></pre>
  
  <p>But then when I want to get the value of <code>r</code> it gives me one more value than it actually is. Also, when I copy the values from one Array to the other there is a value that it is skipping one value. I know everything has to do with the value of <code>r = (r+1)%(q.length);</code> and I've been working on it for hours and can't figure it out.
  After assigning the value to q[r], even if it is only the first value, and I try to get the value of where r should be it gives me 1 because it is increased by the formula, but I can't figure out how to write it in a different way without messing up the circular queue formula.
  Any help would be greatly appreciated. Thanks!</p>