Here i have create a delete method that will search through the Object array and remove the selected object.
public class DogList {
private int numItems;
private DogItem[] dogListArray;
private int position;
private String name;
DogList () {
numItems=0;
position = 0;
dogListArray = new DogItem[20];
}
DogList(String name) {
this.name = name;
}
public void deleteItem(DogList gi) {
int i = 0;
while( (i < numItems) && (gi != dogListArray[i]) ) {
i++;
}
if(i == numItems) {
// Throw exception if there is not matching Item
throw new NoSuchElementException("That item does not exists");
}
int pos = i;
while(pos < numItems -1 ) {
dogListArray[pos] = dogListArray[pos + 1];
pos++;
}
numItems --;
}
I cant wrap my head around why in the first while loop the (gi != dogListArray[i])
is throwing an error:"Incompatible operand types DogList and DogItem"
Any help would be wonderful. The code is pretty long so if you want to see any part i will edit and show what is needed.