#java annalyn infiltration

1 messages · Page 1 of 1 (latest)

lusty minnow
#

Hello, I need help with this exercise, I can't pass the test, this is the code, if someone tells me what I'm doing wrong I would appreciate it.
public static boolean canFreePrisoner(boolean knightIsAwake, boolean archerIsAwake, boolean prisonerIsAwake, boolean petDogIsPresent) {
if ((!knightIsAwake !archerIsAwake !prisonerIsAwake) && petDogIsPresent) {
return true;
} else {
return false;
}

}
vast quartzBOT
wispy pond
#

Please also include any errors.

lusty minnow
#

this is the error in the test 7
Message:
Expecting:
<true>
to be equal to:
<false>
but was not.
Exception: org.opentest4j.AssertionFailedError:
Expecting:
<true>
to be equal to:
<false>
but was not.
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at AnnalynsInfiltrationTest.cannot_release_prisoner_if_only_prisoner_is_asleep_and_pet_dog_is_present(AnnalynsInfiltrationTest.java:318)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
and this is the test 20
Message:
Expecting:
<false>
to be equal to:
<true>
but was not.
Exception: org.opentest4j.AssertionFailedError:
Expecting:
<false>
to be equal to:
<true>
but was not.
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at AnnalynsInfiltrationTest.can_release_prisoner_if_only_prisoner_is_awake_and_pet_dog_is_absent(AnnalynsInfiltrationTest.java:210)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)

wispy pond
#

You should use a code block 🙂 it makes things much easier to read

lusty minnow
#

I don't know what I have to change in the code for it to work.

wispy pond
#

Did you click the link above?

lusty minnow
#

sorry I don't know how to handle this very well

wispy pond
#

When given a link, it is usually helpful to follow the link and read the suggested material.

lusty minnow
#

OK thanks

wispy pond
#

Message: 
Expecting:
 <true>
to be equal to:
 <false>
but was not.
Exception: org.opentest4j.AssertionFailedError: 
Expecting:
 <true>
to be equal to:
 <false>
but was not.
 AnnalynsInfiltrationTest.can_release_prisoner_if_only_prisoner_is_awake_and_pet_dog_is_absent(AnnalynsInfiltrationTest.java:210)
    at java.base/
#

If only the prisoner is awake and the dog is absent, the function is expected to return false. Instead, it returns true.

#

Do you understand why it is supposed to be false? Do you understand why your code returns true?