• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Trouble creating a boolean method

 
André Asantos
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



Why are there some compilation errors?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Rob Spoor
Sheriff
Pie
Posts: 20661
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12196
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic