• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Trouble creating a boolean method

 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



Why are there some compilation errors?
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic