In my class I have set the member variable honey as follows:
int honey = 10;
What I want the following method to do is take as a parameter the amount of hooney required and either return that amount if it is available and remove the specified amount from the stores or return 0 if there is no honey to be had. My method is as follows:
public int takeHoney(int h2){
if(h2 <= honey){
honey = honey - h2;
return h2;
}else{
return 0;
}
}
When my test harness does this:
h.takeHoney(Integer.MAX_VALUE);
it does not go down the if branch as I wanted it to but down the else branch. Why is this? Surely as it is using Integer.MAX_VALUE it is removing the exact value that is in the hive and therefore h2<= honey as it equals honey?