PLAYING CAT

 The cat spends most of the day playing. In particular, they play if the temperature id between 25 and 35 (inclusive). Unless it is summer, the upper limit is 45 (inclusive) instead of 35.

Write a method of isCatPlaying that has two parameters. The method needs to return true if it is playing, otherwise, return false.

1st parameter is of type boolean and is named summer it represents summer. 2nd is named temperature of type int representing the temperature.

Soln : 

package com.cnc;
public class Main {

public static void main(String[] args) {
System.out.println(isCatPlaying(true, 10));
System.out.println(isCatPlaying(false, 36));
System.out.println(isCatPlaying(false, 35));

}

public static boolean isCatPlaying(boolean summer, int temperature) {
if(summer){
if (temperature<=45 && temperature>=25) {
return true;
}else return false;
}else {
if(temperature<=35 && temperature>=25){
return true;
}else return false;
}
}
}

Popular posts from this blog

NUMBER PALINDROME CHALLENGE

ENCAPSULATION CHALLENGE

LARGEST PRIME FACTOR OF A NUMBER