-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlayingCat.java
39 lines (31 loc) · 1.49 KB
/
PlayingCat.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// The cats spend most of the day playing. In particular, they play if the temperature is between 25 and 35 (inclusive). Unless it is summer, then the upper limit is 45 (inclusive) instead of 35.
// Write a method isCatPlaying that has 2 parameters. Method needs to return true if the cat is playing, otherwise return false.
// 1st parameter should be of type boolean and be named summer it represents if it is summer.
// 2nd parameter represents the temperature and is of type int with the name temperature.
// EXAMPLES OF INPUT/OUTPUT:
// isCatPlaying(true, 10); should return false since temperature is not in range 25 - 45
// isCatPlaying(false, 36); should return false since temperature is not in range 25 - 35 (summer parameter is false)
// isCatPlaying(false, 35); should return true since temperature is in range 25 - 35
public class PlayingCat {
public static boolean isCatPlaying(boolean summer, int temperature) {
if (summer == true) {
if (temperature >= 25 && temperature <= 45) {
return true;
}
else
return false;
}
else {
if (temperature >= 25 && temperature <= 35) {
return true;
}
else
return false;
}
}
public static void main(String[] args){
System.out.println(isCatPlaying(true,10));
System.out.println(isCatPlaying(false,36));
System.out.println(isCatPlaying(false,35));
}
}