title: Using for loop for an ArrayLIst in Java (Blue J)?
body: <p>Basically I've been having difficulty using a for loop to find the largest magnitude of an earthquake stored in an arraylist in class observatory. I get an error telling me that the variable "i" in my for loop cannot be found for the method to find the largest magnitude recorded by the observatory. </p>
  
  <pre><code>class Observatory
  {
  private String name;
  private String country;
  private int yearStarted;
  private int area;
  private int runningTotal;
  private ArrayList&lt;Earthquake&gt; earthquakes;
  private ArrayList&lt;String&gt; observatories;
  Scanner userInput = newScanner(System.in);
  
  private double largestMag(ArrayList&lt;Earthquake&gt; earthquake, double magnitude)
  {
  
      if (earthquake == null || earthquake.isEmpty()){
          return 0;
      }
      for (Earthquake quake : earthquake) {
          if (earthquake.get(0) &lt; earthquake.get(i)){
              return earthquake.get(i);
          }
          if (earthquake.get(0) &gt; earthquake.get(i)){
              return earthquake.get(0);
          }
      }      
  }
  </code></pre>
  
  <p>I know its something to do with the fact that in my earthquake class you add the earthquakes the array list is storing more than one piece of information?</p>
  
  <p>this is my earthquake class</p>
  
  <pre><code>public class Earthquake
  {
  // instance variables - replace the example below with your own
  private double magnitude;
  private double latitude;
  private double longitude;
  private int yearOfEvent;
  private String position;
  private String details;
  
  
  
  
  public Earthquake()
  {
      magnitude = 0;
      latitude = 0;
      longitude = 0;
      yearOfEvent = 0;
  
  }
  
  public void setMagnitude(double magnitude)
  {
      this.magnitude= magnitude;
  }
  
  public double getMagnitude()
  {
      return magnitude;
  }
  
  public void setYear(int yearOfEvent)
  {
      this.yearOfEvent = yearOfEvent;
  }
  
  public int getYear()
  {
      return yearOfEvent;
  }
  
  public void setPosition(double latitude, double longitude)
  {
      this.latitude = latitude;
      this.longitude = longitude;
  }
  
  public String getPosition()
  {
     position = latitude + ", " + longitude;
     return position;
  }
  
  public String getDetails()
  {
      details = magnitude + " ," + latitude + "," + longitude + ","+ yearOfEvent;
      return details;
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I'm not sure how to get round the problem of pulling out the magnitude from the array list to use for calculations in my method. thanks. </p>