title: How can I remove items from arrayList by StudentID?
body: <p>I need to write a method that removes students from the ArrayList (myRoster) by student ID. If the student ID doesn't exist, the method should print an error message indicating that it is not found. I have written a remove method where I'm able to remove item by index. The error message 'Student with ID 3 was not found' is returning 6 times (3 from first remove and 3 from second error message). But I want to get one error message for second remove method which I'm calling in main method. A little help would be much appreciated.   </p>
  
  <p><strong>Student Class</strong></p>
  
  <pre><code> public class Student {
      private int StudentID;
      private String FirstName;
      private String LastName;
      private String Email;
      private int age;
      private int[] Grades;
  
      //Constructor
      public Student(int S_ID,String fName,String lName,String email,int Age, 
      int[] grade){
          setStudentID(S_ID);
          setFirstName(fName);
          setLastName(lName);
          setEmail(email);
          setAge(Age);
          setGrade(grade);
      }
      //Accessor Methods (get methods) 
      public int getStudentID(){
          return StudentID;
      }
      public String getFirstName(){
          return FirstName;
      }
      public String getLastName(){
          return LastName;
      }
      public String getEmail(){
          return Email;
      }
  
      public int getAge(){
          return age;
      }
      public int[] getGrades(){
          return Grades;
      }
  
      //Mutator methods (set methods)
  
      public void setStudentID(int StudentID){
          this.StudentID=StudentID;
      }
      public void setFirstName(String FirstName){
          this.FirstName=FirstName;
      }
  
      public void setLastName(String LastName){
          this.LastName=LastName;
      }
      public void setEmail(String Email){
          this.Email=Email;
      }
      public void setAge(int age){
          this.age=age;
      }
      public void setGrade(int Grade[]){
          this.Grades=Grade; 
      }
  
  }
  </code></pre>
  
  <p><strong>Roster Class</strong></p>
  
  <pre><code> import java.util.ArrayList;
  
  
      public class Roster {
      private static ArrayList&lt;Student&gt; myRoster= new ArrayList&lt;&gt;();
      public static void main(String[] args) {
          add(1,"John", "Smith", "John1989@gmail.com", 20, 88,79, 59);
          add(2,"Suzan", "Erickson", "Erickson_1990@gmailcom",19,91,72,85);
          add(3,"Jack","Napoli","The_lawyer99yahoo.com",19,85,84,87);
          add(4,"Erin", "Black","Erin.black@comcast.net",22,91,98,82 );
          add(5,"Henry","Adam","adam1@gmail.com",25,85,84,79);
  
  
          remove(3);
  
          remove(3);//expected: This should print a message saying such a student with this ID was not found
  
      }
  
      public static void add(int S_ID,String fName,String lName,String email,int 
      Age, int grade1, int grade2, int grade3){
          int[] Grades={grade1, grade2,grade3};
          Student newStudent= new Student(S_ID, fName, lName, email, Age, Grades);
          myRoster.add(newStudent);
      }
  
  
  
      public static void remove(int StudentID){
            for (int i = 0; i &lt; myRoster.size(); i++){
                if(i == StudentID){
                   myRoster.remove(i);
                }else{
          System.out.println("Student with ID "+StudentID+" was not found");
                }
            }
      }
  
  
      }
  
  }
  </code></pre>