File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Trouble creating a boolean method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Trouble creating a boolean method" Watch "Trouble creating a boolean method" New topic

Trouble creating a boolean method

André Asantos
Ranch Hand

Joined: Nov 23, 2009
Posts: 234

Why are there some compilation errors?
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63857

When asking question of this type, it's best to include the errors that you are getting rather than making people guess.

But in this case, look closely at your code. How are lines 9 and 13 supposed to execute?

[Asking smart questions] [About Bear] [Books by Bear]
Rob Spoor

Joined: Oct 27, 2005
Posts: 20274

Where to start... Oh wait, at the top!

Line 6. Your method signature needs types for the parameters. Either add "double " before both parameters, or drop the parameters altogether since you're not using them anyway.

Line 11. else with a guard is not allowed. Change it into "else if (this.saldo < this.valor)".

Line 9, 13. Code directly after a return will never ever be executed, so it's simply not allowed. Move the return statement to after the print-outs.

Line 15. What will be returned if this.saldo == this.valor? You'll need to return something there as well.
Note that the compiler isn't smart enough to see that if you change line 11 to "else if (this.saldo <= this.valor)" you actually have covered all cases. It will still think that it's possible that there is a third option, so you'll need a return statement.

How To Ask Questions How To Answer Questions
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11955

The answer to the question you asked is "Because your code doesn't follow proper syntax".

People here will bend over backwards to help you (as Bear and Rob have already done). Your job is to make it as easy for them to help you as possible. That includes posting the error messages your got, what SPECIFICALLY you don't understand, and as much other information as you can.

Generally speaking, posting something along the lines of "This doesn't work" will be met with silence.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
I agree. Here's the link:
subject: Trouble creating a boolean method
It's not a secret anymore!