Reputation: 1
Im attempting to remove an object form an array list but if fails everytime. Im using a function to add and a seperate one to remove. The add function is working but the remove is not. I cant see where it is going wrong and failing.
public void unregister( Basics classToRemove){
if(checkIsRegistered(classToRemove)){
getClassList().remove(classToRemove);
System.out.println(getClassList().remove(classToRemove));
System.out.println("You have unregistered from " + classToRemove.className + " class.");
setTotalTuition();
} else{
System.out.println("\nYou are not currently registered for " + classToRemove.className + " class.\n");
}
}
public void register(Basics classToAdd){
if(!checkIsRegistered(classToAdd)){
getClassList().add(classToAdd);
System.out.println("You have registered for " + classToAdd.className + " class.");
setTotalTuition();
}else{
System.out.println("\nYou are already registered for " + classToAdd.className + " class.\n");
}
}
I have attempted using this.arrayList to remove the object and using getters to get the object and remove it.
Upvotes: 0
Views: 79
Reputation: 398
You can not just print a class-object with System.out.printline
. I assume you want to print the attributes of the class, however you are printing the memory address of the object.
Additionally, this doesn't make sense to me:
getClassList().remove(classToRemove);
System.out.println(getClassList().remove(classToRemove));
You can't access and print an Object you just removed.
If this is not helpful, consider providing a minimal example and explaining what exactly is not working.
Upvotes: 2