• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Class, Method Help

 
Alvado Bain
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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]

 
Manoj Kumar Jain
Ranch Hand
Posts: 198
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • 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 ??
 
Matthew Brown
Bartender
Posts: 4567
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to The Ranch!
 
Alvado Bain
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are you saying? elaborate for me.

 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • 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
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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
  • Quote
  • Report post to moderator
Thank you all for your support.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic