so i'm super stuck. I have a list of students with fname lname sNum etc. i'm trying to use my remove function and it doesn't work. i can't figure out where my problem is.
public void removeStudent(long sNumber) {
//create student object
Student student = new Student();
//loop through the students
for (int i = 0; i < this.students.size(); i++) {
//display students
System.out.println(this.students.get(i));
//condition if sNumber == sNumber
if(student.getsNumber() == sNumber){
//remove the student from the list
this.students.remove(student);
System.out.println(this.students.get(i));
}
System.out.println("skipped the if statement");
}
/*for(Student student : this.students){
if(student.getsNumber() == sNumber){
this.students.remove(student);
}
}*/
}
this is where i call the method
case 3:
// delete a student
System.out.print("What is the Students sNumber: s");
long sNum = input.nextLong();
Student chkSNum = new Student();
registry.getStudentBySNumber(sNum);
chkSNum.setsNumber(sNum);
if (registry.getStudentBySNumber(sNum) == chkSNum) {
if (chkSNum.getsNumber() == sNum) {
registry.removeStudent(sNum);
System.out.println(chkSNum);
}
} else {
System.out.println("Sorry no matches");
// System.out.println(sNum);
System.out.println(registry.getStudentBySNumber(sNum));
System.out.println(chkSNum);
}
break;
my add student method works just fine.
public void addStudent(Student student) {
this.lastSNumber++;
student.setsNumber(this.lastSNumber);
this.students.add(student);
}