Skip to content

Instantly share code, notes, and snippets.

@0ryant
Created August 1, 2019 09:40
Show Gist options
  • Save 0ryant/ba8a845221d8b69b6d20750d882732d9 to your computer and use it in GitHub Desktop.
Save 0ryant/ba8a845221d8b69b6d20750d882732d9 to your computer and use it in GitHub Desktop.
Java - Coding Challenge 3 - Barking dog
public class BarkingDog {
public static boolean shouldWakeUp(boolean barking,int hourOfDay){
if (hourOfDay <0 || hourOfDay >23){
return false;
}
if (barking == true && hourOfDay <8 || hourOfDay >22){
return true;
}else{
return false;
}
}
}
@travelonether
Copy link

All the different code layout examples are great to see to improve. Thanks for the share.

@ilialloyd
Copy link

ilialloyd commented Aug 30, 2022

public class BarkingDog {
    public static boolean shouldWakeUp(boolean barking , int hourOfDay){
       if (hourOfDay >= 0 && hourOfDay <= 23) {        // to check right hour number
            if (hourOfDay <= 7 || hourOfDay >= 23) {       // to check barking hours
                return barking;      //flag to true if its during bark hours
            }
        }else{
            return false;       //out barking hours entry flag false
        }
        return false;          // flag false if invalid hour 
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment