File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Class, Method Help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Class, Method Help" Watch "Class, Method Help" New topic
Author

Class, Method Help

Alvado Bain
Greenhorn

Joined: Apr 11, 2012
Posts: 5
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

Joined: Aug 22, 2008
Posts: 193

Have a look at your method and its If condition



Do you think that the "If" will be evaluated to false in any case ??


Do not wait to strike till the iron is hot; but make it hot by striking....
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4467
    
    8

And welcome to The Ranch!
Alvado Bain
Greenhorn

Joined: Apr 11, 2012
Posts: 5
What are you saying? elaborate for me.

Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

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

Joined: Aug 22, 2008
Posts: 193

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

Joined: Apr 11, 2012
Posts: 5
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

Joined: Jan 03, 2004
Posts: 6109
    
    6

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

Joined: Apr 11, 2012
Posts: 5
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

Joined: Jan 03, 2004
Posts: 6109
    
    6

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

Joined: Apr 11, 2012
Posts: 5
Thank you all for your support.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Class, Method Help