#Beginner JAVA - if / else statements

4 messages · Page 1 of 1 (latest)

high prism
#

Hi everyone - still on the adventure of learning Java as a first language and its something else.
I've come across the exercise from University and was wondering if theres a easier way for me to approach it than the way I am approaching it.

#

The prompt above

#

My current approach is to setup 2 sets of variables, set 1 and set 2 for temp/rain/humidity

My question is regarding the outcome result, now obviously - depending on the input, all 3 of rain, humidity and temp are rated from 3-2-1, my approach was as follows:

        if ((temperature >= 15) || (temperature <= 25)) {
            sTemp1 = 3;
        } else if (temperature < 15) {
            sTemp1 = 2;
        } else {
            sTemp1 = 1;
        }

        if ((rain >= 0 ) || (rain <= 3)) {
            sRain1 = 3;
        } else if ((rain >= 4) || (rain <= 8)) {
            sRain1 = 2;
        } else {
            sRain1 = 1;
        }