Note that there are some explanatory texts on larger screens.

plurals
  1. POArrayList and methods for java
    text
    copied!<p>I have been working on this for hours so I hope someone can help me. I have to create an arraylist of students and do the following commands. add, find and delete students. Anyways my add, find functions work ok, but when I try to delete students it brings up the wrong student! I dont' know what to do feels like I have tried everything.</p> <pre><code>public void addStudent(String studentName, long studentID, String address) { Student newStudent = new Student ( studentName, studentID, address); collegeList.add(newStudent); } public static void deleteStudent() { Scanner input=new Scanner(System.in); System.out.print("Enter student ID"); long studentNumber=input.nextLong(); if(directory.isValidID(studentNumber) &amp;&amp; directory. withinRange(studentNumber)) { System.out.print("Deleting Student"); System.out.print(directory.findStudent(studentNumber)); System.out.print("please confirm with y/n"); Scanner myans=new Scanner(System.in); String confirmation=myans.next(); if (confirmation.equals("y")) { directory.deleteStudent(studentNumber); System.out.print("student deleted"); } if(confirmation.equals("n")) { System.exit(0); } } } /** Searches for student based upon their student number @param studentID unique student number for each student @return students entire information */ public String findStudent(long studentID) { String str; Student newStu; for (int i=0; i&lt;collegeList.size(); i++ ) { newStu=collegeList.get(i); if(newStu.getStudentID()==studentID); return newStu.toString(); } return null; } /** Removing student from collegeList @param studentID unique student number @return none */ public void deleteStudent (long studentID) { Student newStu; for (int i=0; i&lt;collegeList.size(); i++ ) { newStu=collegeList.get(i); if (newStu.getStudentID()==studentID) collegeList.remove(i); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload