title: Simple ArrayList program-JAVA
body: <p>I'm trying to solve this question:</p>
  
  <blockquote>
    <p>Define a class Student with attributes studentID and marks in the module 1030Y. The class Student must also contain a default constructor along with a constructor to initialize an object of type Student with user-defined values, mutator and accessor methods for each attribute and a display method. Write a test program that maintains an ArrayList of Student objects (with IDs in the range 701-799 and marks in the range 0.0 to 100.0). The program will allow the user to input the student id number and the mark for each student. After all the input has been done, the program will display the ids of the students with the highest and the lowest marks.</p>
  </blockquote>
  
  <p>For some reason the part where i'm trying to get the lowest and highest mark of the students is not working.</p>
  
  <p>Here's my codes:
  <br/>Student.java:</p>
  
  <pre><code>package Number5;
  
  public class Student {
  private int studentID;
  private float mark;
  
  public Student()
  {
      studentID = 0;
      mark = 0;
  }
  
  public Student(int id, float marks)
  {
      this.studentID = id;
      this.mark = marks;
  }
  
  public void setID(int id)
  {
      this.studentID = id;
  }
  
  public int getID()
  {
      return studentID;
  }
  
  public void setMark(float marks)
  {
      this.mark = marks;
  }
  
  public float getMark()
  {
      return mark;
  }
  
  public void display()
  {
      System.out.println("Student ID: "+getID());
      System.out.println("Marks: "+getMark());
  }
  }
  </code></pre>
  
  <p>testStudent.java:</p>
  
  <pre><code>package Number5;
  import java.util.ArrayList;
  import java.util.Scanner;
  
  public class testStudent {
  
  public static void main(String[] args) {
      ArrayList&lt;Student&gt; students = new ArrayList&lt;Student&gt;();
      int id=0; float mark=0;
      Scanner input = new Scanner(System.in);
  
      do
      {
          System.out.print("Enter the student ID: ");
          id = input.nextInt();
          System.out.print("Enter the marks: ");
          mark = input.nextFloat();
          students.add(new Student(id,mark));
      }
      while(id != 0 || mark != 0);
  
      int smallest = 9999, largest = -9999;
  
      for(int i=0; i&lt;students.size(); i++)
      {
          while(smallest &gt; students.get(i).getMark())
          {
              smallest = students.get(i).getID();
          }
  
          while(largest &lt; students.get(i).getMark())
          {
              largest = students.get(i).getID();
          }
      }
  
      System.out.println("Smallest is "+smallest);
      System.out.println("Largest is "+largest);
  }
  }
  </code></pre>
  
  <p>The program just stops after reading the user input. It doesn't even go until the for loop.</p>