Boolean birds

isFlobbyBird

Okay

public boolean isFlobbyBird(boolean red, boolean spotted){
  if (red && spotted) {
    return true;
  } else {
    return false;
  }
}

This is fine but the if statement is superfluous.

red && spotted is already a boolean value. Just return it.

Also okay

public boolean isFlobbyBird (boolean a, boolean b){
  return a && b;
}

This also works and is nice and concise.

However the variable names are not very meaningful.

I can’t read the line return a && b; and get any sense of what it means to be a Flobby bird.

Perfect

public boolean isFlobbyBird(boolean red, boolean spotted) {
  return red && spotted;
}

Lovely! Concise and meaningful.

isBloggyBird

Okay

public boolean isBloggyBird(boolean red, boolean spotted) {
    return red == true && spotted == false;
}

Don’t compare to boolean literals.

If you need this …

red == true

… why not this?

(red == true) == true

… or this?

((red == true) == true) == true

Closer

public boolean isBloggyBird(boolean red, boolean spotted) {
  return red && !spotted == true;
}

Good job using ! but then gave into temptation to compare to a literal.

Perfect

public boolean isBloggyBird(boolean red, boolean spotted) {
  return red && !spotted;
}

eatsWorms

One way

public boolean eatsWorms(boolean red, boolean spotted){
  return (red && spotted) || (red && !spotted) || (!red && spotted);
}

This is basically combining the three expressions that identify the birds that do eat worms.

Which is perfectly logical.

Let's simplify

(r && s) || (r && !s) || (!r && s)

(r && s || r && !s) || !r && s

(r && (s || !s)) || !r && s

(r && true) || !r && s

r || !r && s

r || s

Thus one simple way

public boolean eatsWorms(boolean red, boolean spotted){
  return red || spotted;
}

Can also get here by looking at the descriptions.

All the red birds eat worms.

All the spotted birds eat worms.

Therefore if a bird is red or spotted it eats worms.

Another, maybe even better

public boolean eatsWorms(boolean red, boolean spotted) {
  return !isGlobbyBird(red, spotted);
}

Honorable mention

public boolean eatsWorms(boolean red, boolean spotted){
  return !(!red && !spotted);
}

This person wrote isGlobbyBird as:

public boolean isGlobbyBird(boolean red, boolean spotted){
  return !red && !spotted;
}

So they clearly negated that expression.

Let's simplify

!(!red && !spotted)

!!red || !!spotted

red || spotted

isRed

Got the key idea

public boolean isRed(String birdie) {
  if (birdie.equals("Flobby") || birdie.equals("Bloggy")) {
    return true;
  } else {
    return false;
  }
}

What’s could be improved?

Perfect

public static boolean isRed(String name) {
  return name.equals("Flobby") || name.equals("Bloggy");
}

Why doesn't this work?

public static boolean isRed(String name) {
  return name.equals("Flobby" || "Bloggy");
}

Forgot equals?

If you forgot equals you could build it from parts.

public boolean isRed(String bird) {
  return bird.indexOf("Flobby") >= 0 || bird.indexOf("Bloggy") >= 0;
}

This depends on the fact that the argument is guaranteed to be one of just four strings.

Which is fine in this case.