• Post Reply Bookmark Topic Watch Topic
  • New Topic

How do I get my ATM class to withdraw the correct ammounts  RSS feed

 
David Vach
Ranch Hand
Posts: 105
3
Chrome Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, so pretty much my problem is a simple logic one that I am not seeing right now. I want my ATM to withdraw amounts that are only multiples of 20, for it to not withdraw more then is available in the current account, and for it to withdraw amounts less then or equal  to the balance. However, it is not doing this. It is giving me the response that is reserved for when the amount is more then the available balance, every time. I am not really sure why this is. The error should be in the else if statement in line 116 titled options==3. Here is my code:

 
Lalit Sahu
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had executed your program .i find one problem in it i.e negative balance. You want to stop transaction when withdraw money is greater than available balance.
 
Lalit Sahu
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Resolved your problem  transaction which would not stop when withdrawal amount greater than current Balance causing negative balance in your account.

Few Changes made from line 118 that is else if(option ==3) block

Now it working as expected.
 
David Vach
Ranch Hand
Posts: 105
3
Chrome Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here are my if statements. If you look at the third one, I already have one that says if the withdraw is greater then the balance, to print that phrase. What am I missing? It still print out negative values:



 
David Vach
Ranch Hand
Posts: 105
3
Chrome Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Disregard last post, didnt see your last post. let me see if it works on my end.
 
David Vach
Ranch Hand
Posts: 105
3
Chrome Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It works! Thanks for the help!
 
David Vach
Ranch Hand
Posts: 105
3
Chrome Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wait hold on. Now I'm getting the problem that if I try to withdraw the current balance, it gives the pop up that I am not allowed to take out more then is in my account. I tried to get rid of the error by deleting the equals sign in your



by going like

if(atm.withdraw>atm.balance)
                {
                    System.out.println("You are not allowed to take out more then you have in your account \nPlease retry");
                    atm.balance+=atm.withdraw;
                }
but that didn't work. It doesnt allow me to take out more then the balance anymore, but now it doesn't allow me to take out the balance.
 
David Vach
Ranch Hand
Posts: 105
3
Chrome Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wait hold on. Now I'm getting the problem that if I try to withdraw the current balance, it gives the pop up that I am not allowed to take out more then is in my account. I tried to get rid of the error by deleting the equals sign in your



by going like


but that didn't work. It doesnt allow me to take out more then the balance anymore, but now it doesn't allow me to take out the balance.
 
David Vach
Ranch Hand
Posts: 105
3
Chrome Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually I don't seem to be able to withdraw anything.
 
David Vach
Ranch Hand
Posts: 105
3
Chrome Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pretty much what I have figured out is still the issue is if you try to withdraw all your money, it will not let you. It wont go negative thankfully but it won't let you withdraw all of your money. It is also very odd about the amounts it does let me withdraw. Sometimes it lets me withdraw small amounts and other times large amounts.
 
David Vach
Ranch Hand
Posts: 105
3
Chrome Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I figured out what the issue is. It will not let you withdraw more than half of your money.
 
Piet Souris
Master Rancher
Posts: 2044
75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And you know why? Because you first withdraw deposit from the balance, before you do any checks. For instance,  you have that balance = balance - withdraw. Then you check: if withdraw > balance ... Can you figure out where this factor of 0.5 is coming from?

So first do the checks, and then decide if a withdraw is possible. Do you round withdraw, as a multiple of 20, up or down?
 
David Vach
Ranch Hand
Posts: 105
3
Chrome Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I ended up just rewriting my options==3 as the logic simply was not making sense the way I wanted it to. It ended up working. Thanks for the help though.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!