Coding Exercise 3: Barking Dog
2021. 2. 18. 20:11ㆍJava programming
Barking Dog
We have a dog that likes to bark. We need to wake up if the dog is barking at night.
Write a method shouldWakeUp that has 2 parameters.
1st parameter should be of type booleanand be named barking it represents if our dog is
currently barking.
2nd paramter represents the hour of the day and is of type int with the name hourOfDay and has a valid range of 0-23.
We have to wake up if the dog is barking before 8 or after 22 hours so in that case return true.
In all other cases return false.
If the hourOfDay parameter is less than 0 or greater than 23 return false.
public class BarkingDog {
public static boolean shouldWakeUp (boolean barking, int hourOfDay) {
if (barking && hourOfDay < 8 && hourOfDay >= 0) {
return true;
}
else if (barking && hourOfDay > 22 && hourOfDay < 24) {
return true;
}
else if (hourOfDay > 8 && hourOfDay < 22) {
return false;
}
else {
return false;
}
}
}
'Java programming' 카테고리의 다른 글
Coding Exercise 5: Decimal Comparator (0) | 2021.02.23 |
---|---|
Coding Exercise 4: Leap Year Calculator (0) | 2021.02.20 |
Coding Exercise 2: MegaBytes Converter (0) | 2021.02.18 |
Coding Exercise 1: Speed Converter (0) | 2021.02.18 |
Operators, Operands and Expressions (0) | 2021.02.17 |