I created a method which remove the students from a HashMAP. it should throw an exception when the id is null. Did somebody know why it is not working?
public void deleteStudent(String firstName, String lastName, String phoneNumber, String birthDate, PersonGender gender, String id) {
Student student = new Student(firstName, lastName, phoneNumber, birthDate, gender, id);
if (students.containsKey(id)) {
students.remove(id);
}
if (students.containsKey(id == null)) {
throw new NullPointerException("The student does not exist");
}
}
public class Application { public static void main(String[] args) {
StudentRepository myStudent = new StudentRepository();
myStudent.addStudent("St","Rt","0742", "1993.03.04", PersonGender.MALE, "1930303");
myStudent.addStudent("Sr","Ro","0742", "1994.03.04", PersonGender.MALE, "1940304");
myStudent.addStudent("Se","Rb","0742", "1995.03.04", PersonGender.MALE, "1950305");
myStudent.addStudent("Sm","Re","0742", "1996.03.04", PersonGender.MALE, "1950306");
myStudent.deleteStudent("Str","Rob","0742", "1992.03.04", PersonGender.MALE, "null");
myStudent.addStudent("Sr","Ro","0742", "1994.03.04", PersonGender.MALE, "1940304");
myStudent.displayStudents();
}
}
if (id == null) { throw new .... }?id.studentsis created/read, currently it's impossible to understand what's in that variable. 2)containsKey(id == null)is actually the same ascontainsKey(True), ifstudentsis just a set of id's, you can replace it withcontainsKey(null)