Created
August 1, 2019 09:40
-
-
Save 0ryant/ba8a845221d8b69b6d20750d882732d9 to your computer and use it in GitHub Desktop.
Java - Coding Challenge 3 - Barking dog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
} |
RaynNaj
commented
Jul 24, 2021
All the different code layout examples are great to see to improve. Thanks for the share.
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