title: Generic Averaging - need a Generic Type but have an int instead
body: <p>I'm trying to implement an abstract generic average class.  It must have a concrete method for averaging.  How does one get around the problem of division, dividing the number of elements (which is always an integer) by the sum of the array or array list?  I'm using an array here.  Using an array list has the same issue.  It appears I must supply the array size but I really should not have to.</p>
  
  <p>EDIT:  The generic average class shall have three only methods where E is a generic type:  E add(E f, E s); E divide(E f, E s); and E setToZero().  There shall be one concrete class with a signature of E average(E[] array).  The numbers must be represented as objects of a class, like Integer and Double, not primitives int and double.  I think that changes the tenor of the question.  Thanks for the help so far.  I appreciate this forum. END_EDIT</p>
  
  <p>With the above in mind, this code below compiles but is not what is required.  I believe I've done my due diligence without success looking here.  </p>
  
  <p>EDIT2:  My customer (Java instructor) said he was fine with int as the second argument and had no problem with adding another method to the class.  I do not think the problem was defined well in that is was over constrained and not intended to be.  </p>
  
  <pre><code>public abstract class GenericAverage&lt;E&gt;
  {
      private E sum;
      private E average;
  
      public GenericAverage()
      {
          sum     = setToZero();
          average = setToZero();
      }
  
      public E Average(E[] array, E size) // wrong, it must be "E Average(E[] array)"
      {
          //E thisSize = 0; // which of course won't work
          for (int i = 0; i &lt; array.length; i++) // to get that array length as an E      {
              sum = add(sum, array[i]);
              //thisSize = thisSize + 1; //which will not work
          }
          average = divide(sum, size);
          //average = divide(sum, getSize(array));  // maybe this is the answer I seek?  
          return average;
      }
  
      public abstract E add(E f, E s);
      public abstract E divide(E f, E s);
      public abstract E setToZero();
      //public abstract E getSize(E[] f);  // maybe this is the way to the answer?
  }
  </code></pre>