Coding Bat – parrotTrouble

This exercise requires that the program return the value of true if you are in “trouble” and a value of false if you are not in “trouble”. You are in trouble if the parrots are talking before 07:00am or after 08:00pm.

Here is the code that you start with:

public boolean parrotTrouble(boolean talking, int hour) {
  
}

As you can see, we have a boolean named talking and an integer named hour.

public boolean parrotTrouble(boolean talking, int hour) {
  return (talking && (hour < 7 || hour > 20));
}

The solution uses a nested boolean to see if the time is before 7 OR after 20. It is simultaneously looking to see if the parrots are talking.

We are using an AND to bridge these two boolean statements together because if the parrots are NOT talking, we can’t be in trouble regardless of the time of day.

Leave a Reply

Your email address will not be published. Required fields are marked *