title: How do I find the average and the top grade in an ArrayList in Java?
body: <p>In this piece of code I would like to find out the top mark that a student has got, and also the average of all the marks. The marks are put into an ArrayList by user input. I have half done the double but do not know how to finish it, and I would like to know how to find the top mark.</p>
  
  <p>Thanks.</p>
  
  <pre><code>import java.util.*;
  import java.lang.*;
  class Course
  {
      private ArrayList&lt;Student&gt; people = new ArrayList&lt;Student&gt;();
  
      public void add( Student s )
      {
          people.add( s );
      }
      //Return the number of students who passed (mark&gt;= 40)
      public int pass()
      {
          int count = 0;
          for ( int i=0; i &lt; people.size(); i++ )
  
          {
              int mark = people.get(i).getMark();
              if(mark &lt; 40){
                  count = count +1;
              }
          }
  
          return count;
      }
  
      public int fail()
      {
          int count = 0;
          for ( int i=0; i &lt; people.size(); i++ )
  
          {
              int mark = people.get(i).getMark();
              if(mark &lt; 40){
                  count = count +1;
              }
          }
  
          return count;
      }
  
     public String top()
     {
  
     }
  
      public double average()
      {
          int sum=0;
  
          for (int i=0; i &lt; people.size(); i++ )
          {
              double average = sum / (double) i;
          }
  
          return sum;
      }
  
  }
  </code></pre>