• 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
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

Class, Method Help

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am having a problem with my debit function. Instead of printing "The person has insufficient funds", it just adds a negative to the account.




[Added code tags - see UseCodeTags for details]

 
Ranch Hand
Posts: 198
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have a look at your method and its If condition



Do you think that the "If" will be evaluated to false in any case ??
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And welcome to The Ranch!
 
Alvado Bain
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What are you saying? elaborate for me.

 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Alvado Bain wrote:What are you saying? elaborate for me.





Please describe exactly which conditions make that false. Please provide sample values that will make that false.
 
Manoj Kumar Jain
Ranch Hand
Posts: 198
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Alvado,
You are saying that

"it just adds a negative to the account. "


It means the If condition

in your debit method is evaluating to true always. Can you find out why its being evaluated to true always.
Will you ever find a case where (balance > (balance-amount) will be false ??

Got my point ? there is a bug in your code which causing this trouble..

One suggestion: Also place a check in code so that user can't enter negative values as this is absurd to make transaction with negative values
 
Alvado Bain
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeff Verdegan wrote:

Alvado Bain wrote:What are you saying? elaborate for me.





Please describe exactly which conditions make that false. Please provide sample values that will make that false.



Well i also used the if else Balance < (balance - amount). Wouldn't that do? This worked for me fine in C++, java on the other hand is a handful.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Alvado Bain wrote:

Jeff Verdegan wrote:

Alvado Bain wrote:What are you saying? elaborate for me.





Please describe exactly which conditions make that false. Please provide sample values that will make that false.



Well i also used the if else Balance < (balance - amount). Wouldn't that do?



That's not what I asked.

Mathematically, exactly when will balance > (balance-amount) be false?

This worked for me fine in C++.



Highly unlikely.
 
Alvado Bain
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeff Verdegan wrote:

Alvado Bain wrote:

Jeff Verdegan wrote:

Alvado Bain wrote:What are you saying? elaborate for me.





Please describe exactly which conditions make that false. Please provide sample values that will make that false.



Well i also used the if else Balance < (balance - amount). Wouldn't that do?



That's not what I asked.

Mathematically, exactly when will balance > (balance-amount) be false?

This worked for me fine in C++.



Highly unlikely.



Wow i feel like a fool, i see your point now. HAHAH, pardon my stupidity.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Alvado Bain wrote:
Wow i feel like a fool, i see your point now. HAHAH, pardon my stupidity.



No problem. Glad the lightbulb finally popped on.

And don't feel bad. We've all been there--staring too long at something and just not seeing what's right in front of our faces. I've been doing this a long time and it still happens to me.
 
Alvado Bain
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you all for your support.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic