user2800912
user2800912

Reputation: 123

Returning a boolean value

Say I have a car that has a certain amount of gas in it and if it gets below:

public static final double TESTCLASS = 0.000001;

then it is empty.

How do I represent this with something like this:

public boolean isEmpty(){

}

I've tried doing just this (below), but I get an error with the "<"

public boolean isEmpty(){
    gas < TESTCLASS;
}

Upvotes: 1

Views: 123

Answers (1)

James Williams
James Williams

Reputation: 678

You've missed out the return statement.

public boolean isEmpty(){
    return (gas < TESTCLASS);
}

Putting the Boolean expression in parentheses makes sure it is evaluated as a Boolean - not sure if you really need it in this case though.

PS: It's a good idea to name your variables semantically - so TESTCLASS would be better as "gasLimit" or "emptyGas"

Upvotes: 1

Related Questions