tags:

views:

98

answers:

3

I have to use only Boolean and if statements to determine if a number is between 141 and 185 and whether it is lower or higher than that number. I am stumped.

double maxHR= 220- Double.parseDouble(yearsOld);        //maximum heart rate
double reserveHR=  maxHR- Double.parseDouble(restingHR);         //heart rate reserve
double upperEndZone= (reserveHR*.85)+Double.parseDouble(restingHR);
double lowerEndZone= (reserveHR*.50)+Double.parseDouble(restingHR);

boolean isTargetRateLow= lowerEndZone<= Double.parseDouble(restingHR) ;

Is there a way to put two operators within one boolean statement? I think that would solve my issue.

+3  A: 

Is this what you need?

boolean isInbetween = (x >= lowerEndZone) && (x <= upperEndZone);
zvrba
Yes, thank you!
PJandQ
+3  A: 

By two operators in one boolean statement do you mean :

boolean bool = a <= b && c >= d

As in the AND operator (&&)

lucas1000001
Precisely, thanks!
PJandQ
+3  A: 

Do you mean something like

// determine if x is in [a,b]
bool in_fully_closed_interval = (a <= x) && (x <= b);

// determine if x is in [a,b)
bool in_closed_left_open_right_interval = (a <= x) && (x < b);

// determine if x is in (a,b]
bool in_open_left_closed_right_interval = (a < x) && (x <= b);

// determine if x is in (a,b)
bool in_open_interval = (a < x) && (x < b);

Yes, I KNOW other people have posted this. I do it to show what I consider more readable variations.

John R. Strohm
+1; and with regard to your last statement: you don't need to be so defensive about answering a question. We always welcome good-intentioned contributions.
polygenelubricants