#Eclipse java assignment
1 messages ยท Page 1 of 1 (latest)
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
@peak lance can u provide the english translation of the failing test's description ?
seems like its mostly the same problem, a problem with the the owner check
if u got the actual tests, have a look in there
yea, sadly not everyone reads your language ๐
yeah. i get taht i will try and translate it to english. the test is really big
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
and the method assertDogsOwned ?
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
yeah u shoudlnt change / cheat the test ๐
the remove dog is checking on the wrong owner, its checking on the dog only
oh okay
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 )
yeah thats the part i get anxious about changing
thanks for the help! now i need to try and fix the code
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 ๐