I know my add method is correct:
public void add(Object object) {
if (!contains(object) && size !=maxObjects) {
set[size] = object; size++;
}
else
System.out.println("Already exists.");
}
because I get print outs like:
Set [maxObjects=8, set=[a, 7, null, null, null, null, null, null], count=2]
true (I ask if it contains a value)
false " "
Set [maxObjects=8, set=[a, 7, b, Valencia, 24, s, Victoria, null], count=7]
Set [maxObjects=8, set=[a, 7, b, Valencia, 24, s, Victoria, 4234], count=8]
I have tried two different remove methods that are both the same (one I created; the other I found on Stack in the most similar problem a few days ago.)
1st remove:
public boolean remove(Object object) {
if (contains(object)) {
object = null;
return true;
}
System.out.println("The object doesn't exist to delete.");
return false;
}
The other remove:
public boolean remove(object object) {
for (int i=0; i<(size-1); i++) {
while (!contains(object) && size <= maxObjects) {
set[i] = set[i+1]; size--; return true;
}
}
System.out.println("Doesn't exist.");
return false;
}
Any help would be amazing!
object). Somehow I'm reminded of this comic...