dimanche 24 février 2019

if-statement function that returns boolean

Write a function in Java that implements the following logic: Your cell phone rings. Return true if you should answer it. Normally you answer, except in the morning you only answer if it is your mom calling. In all cases, if you are asleep, you do not answer.

public boolean answerCell(boolean isMorning, boolean isMom, boolean isAsleep)
{
    if (isMom && isMorning && isAsleep)
    {
        return false;
    }
    if ((!isMom) && isMorning && isAsleep)
    {
        return false;
    }
    if (isMorning && isMom && (!isAsleep))
    {
        return true;
    }
    if ((!isMorning) && isMom && isAsleep)
    {
        return false;
    }
    else
    {
        return true;
    }
}

For the code that I have written above, I am only getting 63% problem coverage and I can't figure out why. The feedback that I am receiving is saying that (False, false, true) was true but I was expecting false. and (true, false, false) was true but its also expected to be false.

Aucun commentaire:

Enregistrer un commentaire