#Eclipse java assignment

1 messages ยท Page 1 of 1 (latest)

solemn citrusBOT
#

<@&987246399047479336> please have a look, thanks.

peak lance
#

public boolean setOwner (Owner o) {
if (o == null && this.owner != null) {
Owner previousOwner = this.owner;
this.owner = null;
previousOwner.removeDog(this);
return true;
}
if (this.owner != o) {
Owner previousOwner = this.owner;
this.owner = o;
if (previousOwner != null) {
previousOwner.removeDog(this);
}
o.addDog(this);
return true;
}
return false;
}

public Owner getOwner() {
    return owner;
}public boolean addDog(Dog dog) {
    if (dog != null && !dogs.contains(dog)) {
        dogs.add(dog);
        dog.setOwner(this);
        return true;
    }
    return false;
}
public boolean removeDog(Dog dog) {
    if (dog != null && dogs.contains(dog)) {
        dogs.remove(dog);
        dog.setOwner(null); 
        return true;
    }
    return false;
}

public ArrayList<Dog> getDogs() {
    return new ArrayList<>(dogs); 
}public boolean removeDog(String dogName) {
    Dog dogToRemove = getDog(dogName);
    if (dogToRemove != null) {
        dogs.remove(dogToRemove);
        if (dogToRemove.getOwner() != null) {
            dogToRemove.getOwner().removeDog(dogToRemove);
        }
        return true;
    }
    return false;
}

public boolean removeDog(Dog dog) {
    if (!containsDog(dog)) {
        return false;
    }

    if (dogs.remove(dog)) {
        if (dog.getOwner() != null) {
            dog.getOwner().removeDog(dog);
        }
        return true;
    } else {
        return false;
    }
}public boolean removeOwner(String ownerName) {
    for (int i = 0; i < size; i++) {
        if (owners[i].getName().equals(ownerName)) {
            removeOwnerAtIndex(i);
            return true;
#

the problem is big

merry rapids
#

@peak lance can u provide the english translation of the failing test's description ?

peak lance
#

wait

merry rapids
#

seems like its mostly the same problem, a problem with the the owner check

peak lance
#

here its easier to see

merry rapids
#

if u got the actual tests, have a look in there

merry rapids
peak lance
#

yeah. i get taht i will try and translate it to english. the test is really big

merry rapids
#

impossble

#

u know where it fails so u just need to isolate that

#

and if they are made actaully correct, each test is a seperate method

peak lance
#

yeah ofcourse haha

#

here you go

merry rapids
#

and the method assertDogsOwned ?

peak lance
#

yeah thats not a method that should be in the program i dont know why its there

#

and the test case is unchangeable so i cant change the test case

merry rapids
#

yeah u shoudlnt change / cheat the test ๐Ÿ˜‰

#

the remove dog is checking on the wrong owner, its checking on the dog only

peak lance
#

oh okay

merry rapids
#

if u look at the test, their are 2 owners made, B is set to own a dog , and the test is checking if its possible to remove the dog from A

#

which is possible in your code as u only check the dog's owner

#

( and u also got the method double in your snippet )

peak lance
#

yeah thats the part i get anxious about changing

#

thanks for the help! now i need to try and fix the code

merry rapids
#

dont forget there is version history, or if u do know master / know that, use a notepad or something to safeguard your current code so u can revert it fast if needed ๐Ÿ˜‰